From fe32e397924f71b4fd04ee8e337ac9d594169d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=BClper?= Date: Thu, 18 Jan 2024 14:49:33 +0100 Subject: [PATCH] fix(socialaccount): fix issue #3599 fix issue #3599 by checking before a token update if app instance is saved to database. If not set app instance to None. --- allauth/socialaccount/models.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/allauth/socialaccount/models.py b/allauth/socialaccount/models.py index f300a0df36..37d23fbbfe 100644 --- a/allauth/socialaccount/models.py +++ b/allauth/socialaccount/models.py @@ -307,6 +307,11 @@ def _lookup_by_socialaccount(self): # Update token if app_settings.STORE_TOKENS and self.token: assert not self.token.pk + # check if app does exist in database if not set self.token.app to None + try: + SocialApp.objects.get(id=self.token.app.id) + except SocialApp.DoesNotExist: + self.token.app = None try: t = SocialToken.objects.get( account=self.account, app=self.token.app