-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Load user in a deferred task #1406
fix: Load user in a deferred task #1406
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we Check If the Task ist deferred an the loaf the User all the time ?
Sorry, but I don't understand what you want to do? |
He means, that in case the request is on a deferred task, the current user is automatically loaded. IMHO the user is provided together with the deferred call request. @ArneGudermann's proposal is useful. |
I still have no idea what I should change in this PR. |
src/viur/core/modules/user.py
Outdated
@@ -1312,7 +1312,7 @@ def secondFactorProviderByClass(self, cls) -> UserSecondFactorAuthentication: | |||
def getCurrentUser(self): | |||
session = current.session.get() | |||
|
|||
if session and session.loaded and (user := session.get("user")): | |||
if session and (user := session.get("user")): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if session and (user := session.get("user")): | |
req = current.request.get() | |
if session and (session.loaded or req.is_deferred) and (user := session.get("user")): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do it that way if you like.
But that doesn't really make any difference. If the session is not loaded
, then session.get("user")
is None
anyway and the condition is falsy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it works in your case i think. If the session is not loaded we can get the current user if the request is deferred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, I mean in the non-deferred case it wouldn't matter whether you have
if session and (user := session.get("user")):
or
if session and (session.loaded or req.is_deferred) and (user := session.get("user")):
because if the session is not loaded (session.loaded
is then False
) there is no content in the unloaded session object and the session.get()
cannot load anything and returns the default value None
.
This means that both statements are logically the same.
Co-authored-by: agudermann <[email protected]>
Fixes #1405