You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "moshhi (via GitHub)" <gi...@apache.org> on 2025/06/19 09:52:47 UTC
[D] An error occurs when accessing /users/userinfo/ after deleting a user:AttributeError: 'AnonymousUserMixin' object has no attribute 'id' [superset]
GitHub user moshhi created a discussion: An error occurs when accessing /users/userinfo/ after deleting a user:AttributeError: 'AnonymousUserMixin' object has no attribute 'id'
error detail:
2025-06-19 17:36:36,952:WARNING:superset.views.error_handling:Exception
Traceback (most recent call last):
File "/home/ubuntu/venv/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
File "/home/ubuntu/venv/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/home/ubuntu/venv/lib/python3.10/site-packages/flask_appbuilder/security/decorators.py", line 151, in wraps
return f(self, *args, **kwargs)
File "/home/ubuntu/venv/lib/python3.10/site-packages/flask_appbuilder/security/views.py", line 287, in userinfo
item = self.datamodel.get(g.user.id, self._base_filters)
AttributeError: 'AnonymousUserMixin' object has no attribute 'id'
How can I fix it? @inclusive-coding-bot
GitHub link: https://github.com/apache/superset/discussions/33825
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] An error occurs when accessing /users/userinfo/ after deleting a user:AttributeError: 'AnonymousUserMixin' object has no attribute 'id' [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: An error occurs when accessing /users/userinfo/ after deleting a user:AttributeError: 'AnonymousUserMixin' object has no attribute 'id'
<!-- Answer -->
To override the Flask-AppBuilder userinfo view and avoid the AttributeError, you can subclass the original view and add a check for anonymous users before accessing user attributes. For example, create a custom view that extends the original, override the userinfo method, and check if g.user is anonymous (using g.user.is_anonymous or hasattr(g.user, "id")). If the user is anonymous, redirect to login or show an error; otherwise, proceed as normal.
Here's a minimal example:
```python
from flask import g, redirect, url_for
from flask_appbuilder.security.views import UserDBModelView
class CustomUserInfoView(UserDBModelView):
@expose('/userinfo/')
def userinfo(self):
if not hasattr(g.user, "id") or getattr(g.user, "is_anonymous", False):
return redirect(url_for('AuthDBView.login'))
return super().userinfo()
```
Then, register this custom view with your appbuilder instance, replacing the default one. This pattern is similar to how custom authentication views are created in Superset and Flask-AppBuilder, as shown in [this example](https://github.com/apache/superset/discussions/32038).
This approach ensures that if the user is anonymous (for example, after deletion), the code won't try to access attributes that don't exist, preventing the AttributeError.
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
---
<sup>How did I do? [Good](https://app.dosu.dev/response-feedback/e5bdbc51-d551-4c24-906a-a60a6dbede7b?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/e5bdbc51-d551-4c24-906a-a60a6dbede7b?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/e5bdbc51-d551-4c24-906a-a60a6dbede7b?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/e5bdbc51-d551-4c24-906a-a60a6dbede7b?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/e5bdbc51-d551-4c24-906a-a60a6dbede7b?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/e5bdbc51-d551-4c24-906a-a60a6dbede7b?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/e5bdbc51-d551-4c24-906a-a60a6dbede7b?feedback_type=other)</sup> [](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/33825)
GitHub link: https://github.com/apache/superset/discussions/33825#discussioncomment-13519088
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] An error occurs when accessing /users/userinfo/ after deleting a user:AttributeError: 'AnonymousUserMixin' object has no attribute 'id' [superset]
Posted by "moshhi (via GitHub)" <gi...@apache.org>.
GitHub user moshhi added a comment to the discussion: An error occurs when accessing /users/userinfo/ after deleting a user:AttributeError: 'AnonymousUserMixin' object has no attribute 'id'
"onsider overriding the FAB userinfo view to check for anonymous users before accessing user attributes" how to do this?@dosu
GitHub link: https://github.com/apache/superset/discussions/33825#discussioncomment-13519072
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] An error occurs when accessing /users/userinfo/ after deleting a user:AttributeError: 'AnonymousUserMixin' object has no attribute 'id' [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: An error occurs when accessing /users/userinfo/ after deleting a user:AttributeError: 'AnonymousUserMixin' object has no attribute 'id'
<!-- Answer -->
To override the Flask-AppBuilder userinfo view and avoid the AttributeError, you can subclass the original view and add a check for anonymous users before accessing user attributes. For example, create a custom view that extends the original, override the userinfo method, and check if g.user is anonymous (using g.user.is_anonymous or hasattr(g.user, "id")). If the user is anonymous, redirect to login or show an error; otherwise, proceed as normal.
Here's a minimal example:
```python
from flask import g, redirect, url_for
from flask_appbuilder.security.views import UserDBModelView
class CustomUserInfoView(UserDBModelView):
@expose('/userinfo/')
def userinfo(self):
if not hasattr(g.user, "id") or getattr(g.user, "is_anonymous", False):
return redirect(url_for('AuthDBView.login'))
return super().userinfo()
```
Then, register this custom view with your appbuilder instance, replacing the default one. This pattern is similar to how custom authentication views are created in Superset and Flask-AppBuilder, as shown in [this example](https://github.com/apache/superset/discussions/32038).
This approach ensures that if the user is anonymous (for example, after deletion), the code won't try to access attributes that don't exist, preventing the AttributeError.
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*
---
Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=apache%2Fsuperset).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=apache%2Fsuperset&message_id=e5bdbc51-d551-4c24-906a-a60a6dbede7b) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=apache%2Fsuperset)
GitHub link: https://github.com/apache/superset/discussions/33825#discussioncomment-13519088
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] An error occurs when accessing /users/userinfo/ after deleting a user:AttributeError: 'AnonymousUserMixin' object has no attribute 'id' [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: An error occurs when accessing /users/userinfo/ after deleting a user:AttributeError: 'AnonymousUserMixin' object has no attribute 'id'
<!-- Answer -->
This error happens because Flask-AppBuilder's userinfo view doesn't check if the user is anonymous before accessing g.user.id. When you delete a user but the session remains, g.user becomes an AnonymousUserMixin, which lacks an id attribute, causing the AttributeError.
To fix this: log out and log back in, or clear your browser's session cookies to remove any lingering references to the deleted user. If you have custom session or authentication logic, make sure it handles deleted users gracefully. For a more robust fix, consider overriding the FAB userinfo view to check for anonymous users before accessing user attributes, or update FAB if a patch becomes available. More details and workarounds are discussed [here](https://github.com/apache/superset/discussions/32808).
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*
---
Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=apache%2Fsuperset).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=apache%2Fsuperset&message_id=8ce12568-8684-46b1-9618-6910776b7a21) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=apache%2Fsuperset)
GitHub link: https://github.com/apache/superset/discussions/33825#discussioncomment-13518607
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [D] An error occurs when accessing /users/userinfo/ after deleting a user:AttributeError: 'AnonymousUserMixin' object has no attribute 'id' [superset]
Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: An error occurs when accessing /users/userinfo/ after deleting a user:AttributeError: 'AnonymousUserMixin' object has no attribute 'id'
<!-- Answer -->
This error happens because Flask-AppBuilder's userinfo view doesn't check if the user is anonymous before accessing g.user.id. When you delete a user but the session remains, g.user becomes an AnonymousUserMixin, which lacks an id attribute, causing the AttributeError.
To fix this: log out and log back in, or clear your browser's session cookies to remove any lingering references to the deleted user. If you have custom session or authentication logic, make sure it handles deleted users gracefully. For a more robust fix, consider overriding the FAB userinfo view to check for anonymous users before accessing user attributes, or update FAB if a patch becomes available. More details and workarounds are discussed [here](https://github.com/apache/superset/discussions/32808).
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
---
<sup>How did I do? [Good](https://app.dosu.dev/response-feedback/8ce12568-8684-46b1-9618-6910776b7a21?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/8ce12568-8684-46b1-9618-6910776b7a21?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/8ce12568-8684-46b1-9618-6910776b7a21?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/8ce12568-8684-46b1-9618-6910776b7a21?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/8ce12568-8684-46b1-9618-6910776b7a21?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/8ce12568-8684-46b1-9618-6910776b7a21?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/8ce12568-8684-46b1-9618-6910776b7a21?feedback_type=other)</sup> [](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/33825)
GitHub link: https://github.com/apache/superset/discussions/33825#discussioncomment-13518607
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org