-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove null=True from UserOrigin.origin_id
Possibly a race condition in authentication created duplicate UserOrigin instances for a user with the same data source. Since origin_id was null by default, it didn't hit the data_source & origin_id uniqueness constraint. Null is not handled the same way as an empty string in postgres. With an empty string as the default the duplicate issue, which required manual work to fix, shouldn't happen anymore. Refs: HAUKI-656
- Loading branch information
Showing
4 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 4.2.13 on 2024-07-25 09:41 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("users", "0003_userorigin"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="userorigin", | ||
name="origin_id", | ||
field=models.CharField( | ||
blank=True, default="", max_length=100, verbose_name="Origin ID" | ||
), | ||
preserve_default=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from pytest_factoryboy import register | ||
|
||
from hours.tests.conftest import DataSourceFactory, UserFactory | ||
|
||
register(UserFactory) | ||
register(DataSourceFactory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pytest | ||
from django.db import IntegrityError | ||
|
||
from users.models import UserOrigin | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_user_origin_shouldnt_allow_duplicate_empty_origin_id(user, data_source): | ||
"""Duplicate UserOrigin instances shouldn't get created when data source is | ||
the same but origin_id is empty. | ||
""" | ||
UserOrigin.objects.create(user=user, data_source=data_source) | ||
with pytest.raises(IntegrityError): | ||
UserOrigin.objects.create(user=user, data_source=data_source) |