Skip to content

Commit

Permalink
models: make sure uid is compared case-sensitive
Browse files Browse the repository at this point in the history
The database collation might vary, so use safer comparing in Python.
  • Loading branch information
nijel committed Apr 24, 2024
1 parent 7033ff7 commit 7028c70
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions social_django/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ class Meta:
abstract = True

@classmethod
def get_social_auth(cls, provider, uid):
try:
return cls.objects.select_related("user").get(provider=provider, uid=uid)
except cls.DoesNotExist:
return None
def get_social_auth(cls, provider: str, uid: str):
for social in cls.objects.select_related("user").filter(
provider=provider, uid=uid
):
# We need to compare to filter out case-insensitive lookups in
# some databases (MySQL/MariaDB)
if social.uid == uid:
return social
return None

@classmethod
def username_max_length(cls):
Expand Down

0 comments on commit 7028c70

Please sign in to comment.