-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix(issues): Assert user.id is not None before ORM filter #107744
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ def get(self, request: Request, organization: Organization) -> Response: | |
| Retrieve a list of starred views for the current organization member. | ||
| """ | ||
|
|
||
| assert request.user.id is not None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The assertion Suggested FixReplace the assertion Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm pretty sure api tokens do get user ids. |
||
| starred_views = GroupSearchViewStarred.objects.filter( | ||
| organization=organization, user_id=request.user.id | ||
| ).select_related("group_search_view") | ||
|
|
||
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 should probably return a 4XX error here, instead of an assert which will produce a 500
Uh oh!
There was an error while loading. Please reload this page.
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.
FWIW it is actually impossible for our code to reach here with user id being none as this is an authenticated endpoint. just an annoyance that our type checker can't handle. can see we have a lot of these peppered throughout our endpoints.
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.
Get your point - I think it's fine, but in general I don't love it. We should find a better way of making sure our typing works in these cases
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.
yeah it is not great. I think that it has to do with django/drf typing stubs, where
request.usercan beUserorAnonymousUser. I don't think it's an easy fix.