Skip to content

Commit

Permalink
fix(sonarcloud): use None for verification_token_user_full_name w/o user
Browse files Browse the repository at this point in the history
fix SonarCloud code bug pythonbugs:S2259:
> Fix this attribute access on a value that can be 'None'.
> Attributes should not be accessed on "None" values pythonbugs:S2259

See rule: https://rules.sonarsource.com/python/RSPEC-2259/

Previously obj.user.username was tried to be accessed when obj.user was
None. Now return None when obj.user is None as there's no user, and thus
no username to return either.

refs KK-1416
  • Loading branch information
karisal-anders committed Feb 20, 2025
1 parent 6effbf6 commit 35932bd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions verification_tokens/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from .models import VerificationToken


def verification_token_user_full_name(obj):
def verification_token_user_full_name(obj: VerificationToken) -> str | None:
if obj.user is not None:
return obj.user.guardian.full_name
return obj.user.username
return None


verification_token_user_full_name.short_description = "Name"
Expand Down

0 comments on commit 35932bd

Please sign in to comment.