From 7028c7012b53356444ec82c95f56ec5f2dca31e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 24 Apr 2024 10:26:58 +0200 Subject: [PATCH] models: make sure uid is compared case-sensitive The database collation might vary, so use safer comparing in Python. --- social_django/models.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/social_django/models.py b/social_django/models.py index ab50185c..a5314cb3 100644 --- a/social_django/models.py +++ b/social_django/models.py @@ -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):