Skip to content

Address situations where the UserSettings model instance accompanying a User model instance does not exist #1744

Description

@clpetersonucf

Right now, the ORM gets super duper unhappy when attempting to reference the UserSettings model instance foreign keyed to a User model instance during authentication.

This appears to surface in the save_user_settings receiver attached to the User model:

@receiver(post_save, sender=User)
def save_user_settings(sender, instance, **kwargs):
    instance.profile_settings.save()

Testing on QA indicates something like this may be sufficient:

@receiver(post_save, sender=User)
def save_user_settings(sender, instance, **kwargs):
    try:
        instance.profile_settings.save()
    except UserSettings.DoesNotExist:
        settings = UserSettings.objects.create(user=instance)
        settings.initialize_profile_fields()

But we should ensure all possible edge cases where profile fields can be referenced are similarly equipped to handle a missing UserSettings instance.

Metadata

Metadata

Assignees

Labels

BugThere's a bug.pythonPull requests that update python code

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions