Skip to content

Commit 2a4d46a

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 c50bc4a commit 2a4d46a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 5.0.3 on 2024-03-21 16:01
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("social_django", "0015_rename_extra_data_new_usersocialauth_extra_data"),
9+
]
10+
11+
operations = [
12+
migrations.AddConstraint(
13+
model_name="UserSocialAuth",
14+
constraint=models.CheckConstraint(
15+
check=models.Q(("uid", ""), _negated=True),
16+
name="user_social_auth_uid_required",
17+
),
18+
),
19+
]

social_django/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ class Meta:
8080
app_label = "social_django"
8181
unique_together = ("provider", "uid")
8282
db_table = "social_auth_usersocialauth"
83+
constraints = [
84+
models.CheckConstraint(
85+
check=~models.Q(uid=""), name="user_social_auth_uid_required"
86+
),
87+
]
8388

8489

8590
class Nonce(models.Model, DjangoNonceMixin):

0 commit comments

Comments
 (0)