Skip to content

fix(users): Assert user.id is not None before ORM get#107745

Merged
JoshFerge merged 1 commit intomasterfrom
jferg/fix-authenticator-enroll-none-guard
Feb 6, 2026
Merged

fix(users): Assert user.id is not None before ORM get#107745
JoshFerge merged 1 commit intomasterfrom
jferg/fix-authenticator-enroll-none-guard

Conversation

@JoshFerge
Copy link
Member

@JoshFerge JoshFerge commented Feb 5, 2026

Summary

Found during mypy / django-stubs upgrade in #107710.

Adds assert request.user.id is not None before User.objects.get(id=request.user.id) in the authenticator enrollment endpoint. user.id is typed as int | None.

Test plan

  • Pre-commit hooks pass

Found during mypy / django-stubs upgrade in #107710.
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 5, 2026

# Using `request.user` here because superuser/staff should not be able to set a user's 2fa
if user.id != request.user.id:
assert request.user.id is not None
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annoying we have to do this as this in theory will never be possible, but only way to make the type checker happy.

@JoshFerge JoshFerge marked this pull request as ready for review February 5, 2026 23:41
@JoshFerge JoshFerge requested a review from a team February 5, 2026 23:43
@JoshFerge JoshFerge merged commit ace305c into master Feb 6, 2026
74 checks passed
@JoshFerge JoshFerge deleted the jferg/fix-authenticator-enroll-none-guard branch February 6, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants