-
Notifications
You must be signed in to change notification settings - Fork 0
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
Catch error when no user is set on request #44
Conversation
try: | ||
from superset import security_manager | ||
return security_manager.is_admin() | ||
except AttributeError: | ||
return False |
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.
It bothers me that we have to catch this error, because it's not in our codebase.
What if we first check the user, like so?
try: | |
from superset import security_manager | |
return security_manager.is_admin() | |
except AttributeError: | |
return False | |
from superset import security_manager | |
from flask import g | |
return g.user and security_manager.is_admin() |
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.
It bothers me that we have to catch this error, because it's not in our codebase.
Yeah, but at this stage I'm more prone getting it to work in our code.
The g.user
is the part where it fails hard. Just running g.user
will raise the AttributeError.
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.
Does security manager provide another method on it that we can call to check if there is a user or not before calling is_admin
?
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 instead at least do this
try:
# Check if there is a user first before checking for admin via security manager
g.user
except AttributeError:
return False
return security_manager.is_admin()
try: | ||
from superset import security_manager | ||
return security_manager.is_admin() | ||
except AttributeError: | ||
return False |
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.
Does security manager provide another method on it that we can call to check if there is a user or not before calling is_admin
?
There is a |
Update: the issue was related to the SECRET_KEY not being property configured, hence the user id in the session was wrong. |
Glad that Norman and I pushing back on the change, motivated you to look deeper and find this route cause @Charl1996 🥇 |
True. Sometimes it's worth spending that extra bit of time, even though it's important to get solutions out. Priority != sloppy solution. Anycase, thanks! |
When trying to access
https://commcare-analytics-staging.dimagi.com/
the server responds with a500
. The logs show the error at the bottom.The issue seems to be the fact that
security_manager.is_admin()
doesn't handle no user being set on the request. This PR is really only to catch this error and returnFalse
. I'm not sure why this wasn't picked up before.