Skip to content

Commit cf38c01

Browse files
committed
Add non-empty constraint for UserSocialAuth uid
Any empty uids are surely erroneous, and better to have integrity errors than having users start sharing accounts when logging in.
1 parent 56861b7 commit cf38c01

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 5.1.7 on 2025-03-14 12:16
2+
3+
from django.conf import settings
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("social_django", "0016_alter_usersocialauth_extra_data"),
11+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
12+
]
13+
14+
operations = [
15+
migrations.AddConstraint(
16+
model_name="usersocialauth",
17+
constraint=models.CheckConstraint(
18+
check=models.Q(("uid", ""), _negated=True),
19+
name="user_social_auth_uid_required",
20+
),
21+
),
22+
]

social_django/models.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ def __str__(self):
4343

4444
class Meta:
4545
app_label = "social_django"
46+
constraints = [
47+
models.CheckConstraint(
48+
check=~models.Q(uid=""), name="user_social_auth_uid_required"
49+
),
50+
]
4651
abstract = True
4752

4853
@classmethod
@@ -70,7 +75,7 @@ def user_model(cls):
7075
class UserSocialAuth(AbstractUserSocialAuth):
7176
"""Social Auth association model"""
7277

73-
class Meta:
78+
class Meta(AbstractUserSocialAuth.Meta):
7479
"""Meta data"""
7580

7681
app_label = "social_django"

0 commit comments

Comments
 (0)