Cannot get flask g in trigger_event. #1640
-
I have a global custmom namespace for access control, code:
I cannot use g in trigger_event,any method to fix this issue? |
Beta Was this translation helpful? Give feedback.
Answered by
miguelgrinberg
Jul 21, 2021
Replies: 1 comment 2 replies
-
The App/Request contexts are added when the class SecurityNamespace(Namespace):
def trigger_event(self, event, *args):
super().trigger_event('catchall', event, *args)
def on_catchall(event, *args):
if event == "connect":
print("custom namespace for access control")
# get endpoint
user=g.user #get "Working outside of application context"
endpoint = self.namespace
if check_access(user, endpoint):
super().trigger_event(event, *args)
else:
return
else:
super().trigger_event(event, *args) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
cis1124
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The App/Request contexts are added when the
on_...
method is invoked, so that is correct, the trigger_event method does not have access. You can fix this easily by triggering a fake event: