current_user instance is of LocalProxy type
See original GitHub issueHi, when using current_user instance I was having a weird bug with MongoEngine, then I decided to debug and when checking:
ipdb> type(current_user)
<class 'werkzeug.local.LocalProxy'>
That’s not desired if I will use it directly. MongoEngine complains when using that instance during query/update, etc… Is there any way to unwrap the proxy? Right now I have to query to the DB to get the real object.
Thanks
Issue Analytics
- State:
- Created 11 years ago
- Comments:35 (15 by maintainers)
Top Results From Across the Web
Using Flask-Login for User Management with Flask
I don't think your logout function will work. Per the Flask-Login docs, the current_user object is a proxy of type <class 'werkzeug.local.localproxy'="">.
Read more >firebase - currentUser() is not working type why I am seeing ...
Why do you invoke currentUser as a function ? It is a field, not a method. final user = await _auth.currentUser;. Update: Since...
Read more >API Reference — Flask-Discord 0.1.64 documentation
It uses Flask session local proxy object to save state, authorization token and ... Permissions representing permissions of current user in the guild....
Read more >Context Locals — Werkzeug Documentation (2.1.x)
Use issubclass(type(x), LocalProxy) to check if an object is a proxy. repr(user) # <User admin> isinstance( ...
Read more >flask_login — Flask-Login 0.3.2 documentation
If no user is logged in, this will be an #: anonymous user current_user = LocalProxy(lambda: _get_user()) #: The default name of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
pahaz, the good workaround in my case was to add this mixin to my User class:
And then I could store current_user.self (current_user itself is still the proxy!) in the database. Or, in your case, it would be g.user = current_user.self (you have to test it; I don’t remember if current_user already takes the proper value in before_request handler).
I support your request to reopen the ticket!
@asteinlein there’s nothing stopping you from implementing that yourself. I’m locking this topic now.