Review feedback: exception handling

This commit is contained in:
Neil Martinsen-Burrell 2023-04-04 14:50:36 -05:00
parent ce9c8abd60
commit e4233870d6
No known key found for this signature in database
GPG key ID: 6A3C818CC10D0184
3 changed files with 38 additions and 13 deletions

View file

@ -1,3 +1,5 @@
import logging
from django.contrib.auth.models import AbstractUser
from django.db import models
@ -6,6 +8,9 @@ from .domain_invitation import DomainInvitation
from phonenumber_field.modelfields import PhoneNumberField # type: ignore
logger = logging.getLogger(__name__)
class User(AbstractUser):
"""
A custom user model that performs identically to the default user model
@ -43,5 +48,11 @@ class User(AbstractUser):
for invitation in DomainInvitation.objects.filter(
email=self.email, status=DomainInvitation.INVITED
):
invitation.retrieve()
invitation.save()
try:
invitation.retrieve()
invitation.save()
except RuntimeError:
# retrieving should not fail because of a missing user, but
# if it does fail, log the error so a new user can continue
# logging in
logger.warn("Failed to retrieve invitation %s", invitation, exc_info=True)