penny-university / penny_university

5 stars 6 forks source link

Replace `SocialProfile.objects.get` with `get_or_create_social_profile_from_slack_id` #389

Open JnBrymn opened 3 years ago

JnBrymn commented 3 years ago

There are several places where we might need to retrieve a user''s SocialProfile, but if it's their first interaction with PennyU they might not yet have a social profile, so we need to create it. The easiest way to deal with this is to just replace SocialProfile.objects.get with get_or_create_social_profile_from_slack_id. We also probably need to somehow handicap SocialProfile.objects.get so that we won't accidentally use it directly in the future. Maybe it should raise an error.

Alternatively, maybe the get_or_create_social_profile_from_slack_id pattern is a bad idea. Find something better and use that instead. get_or_create_social_profile_from_slack_id is smelly, but I feel like it might be the best alternative. Otherwise we have to make sure all our Social Profiles are created before their first interaction, which seems unlikely.