Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#317] Prevent saving duplicates #333

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/objects/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
1 change: 0 additions & 1 deletion src/objects/accounts/migrations/0002_auto_20201012_1522.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("accounts", "0001_initial"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/accounts/migrations/0003_auto_20201223_1231.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("accounts", "0002_auto_20201012_1522"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/api/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def __call__(self, attrs):
try:
response = client.retrieve("objecttype", url=object_type.url)
except ClientError as exc:

msg = f"Object type can not be retrieved: {exc.args[0]}"
raise ValidationError(msg)

Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0002_auto_20200518_1707.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0001_initial"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0003_objectrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0002_auto_20200518_1707"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0004_move_data_to_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def move_data_from_record(apps, _):


class Migration(migrations.Migration):

dependencies = [
("core", "0003_objectrecord"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0005_remove_object_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0004_move_data_to_record"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0006_auto_20200904_1402.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0005_remove_object_data"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0007_auto_20200904_1403.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0006_auto_20200904_1402"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0008_objectrecord_correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0007_auto_20200904_1403"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0009_objectrecord_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0008_objectrecord_correct"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0010_move_version_to_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def move_version_from_record(apps, _):


class Migration(migrations.Migration):

dependencies = [
("core", "0009_objectrecord_version"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0011_remove_object_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0010_move_version_to_record"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0012_objectrecord_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0011_remove_object_version"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0013_generate_record_uuids.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def generate_record_uuids(apps, _):


class Migration(migrations.Migration):

dependencies = [
("core", "0012_objectrecord_uuid"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0014_auto_20200915_1740.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0013_generate_record_uuids"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0015_objectrecord_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0014_auto_20200915_1740"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0016_auto_20210111_1649.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0015_objectrecord_geometry"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0017_auto_20210111_1653.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0016_auto_20210111_1649"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0018_auto_20210113_1239.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0017_auto_20210111_1653"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0019_fill_record_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def fill_record_index(apps, _):


class Migration(migrations.Migration):

dependencies = [
("core", "0018_auto_20210113_1239"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0020_auto_20210118_1117.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0019_fill_record_index"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0021_auto_20201222_1745.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("zgw_consumers", "0011_remove_service_extra"),
("core", "0020_auto_20210118_1117"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def move_objecttypes_from_model(apps, _):


class Migration(migrations.Migration):

dependencies = [
("core", "0021_auto_20201222_1745"),
("zgw_consumers", "0011_remove_service_extra"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0022_move_object_types_to_separate_model"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0024_auto_20201222_1811.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0023_remove_object_object_type"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def remove_objects_with_empty_object_type(apps, _):


class Migration(migrations.Migration):

dependencies = [
("core", "0024_auto_20201222_1811"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0026_auto_20201222_1833.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0025_delete_objects_with_empty_object_type"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/core/migrations/0027_auto_20211203_1209.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0026_auto_20201222_1833"),
]
Expand Down
21 changes: 21 additions & 0 deletions src/objects/core/migrations/0028_auto_20230519_1201.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 2.2.28 on 2023-05-19 10:01

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0027_auto_20211203_1209"),
]

operations = [
migrations.AlterField(
model_name="objecttype",
name="_name",
field=models.CharField(
help_text="Cached name of the objecttype retrieved from the Objecttype API",
max_length=100,
unique=True,
),
),
]
1 change: 1 addition & 0 deletions src/objects/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ObjectType(models.Model):
_name = models.CharField(
max_length=100,
help_text=_("Cached name of the objecttype retrieved from the Objecttype API"),
unique=True,
)

objects = ObjectTypeQuerySet.as_manager()
Expand Down
11 changes: 11 additions & 0 deletions src/objects/core/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.db import IntegrityError
from django.test import TestCase

from .factories import ObjectTypeFactory


class ObjectTypeTest(TestCase):
def test_duplicate_name(self):
ObjectTypeFactory.create(_name="test")
with self.assertRaises(IntegrityError):
ObjectTypeFactory.create(_name="test")
1 change: 0 additions & 1 deletion src/objects/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def check_objecttype(object_type, version, data):
try:
response = client.retrieve("objectversion", url=objecttype_version_url)
except ClientError as exc:

msg = f"Object type version can not be retrieved: {exc.args[0]}"
raise ValidationError(msg)

Expand Down
1 change: 0 additions & 1 deletion src/objects/token/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
1 change: 0 additions & 1 deletion src/objects/token/migrations/0002_auto_20201223_1231.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0026_auto_20201222_1833"),
("token", "0001_initial"),
Expand Down
1 change: 0 additions & 1 deletion src/objects/token/migrations/0003_auto_20210312_1507.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("token", "0002_auto_20201223_1231"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/token/migrations/0004_auto_20210315_1537.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("token", "0003_auto_20210312_1507"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/token/migrations/0005_auto_20210623_1242.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("token", "0004_auto_20210315_1537"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/token/migrations/0006_auto_20210721_1543.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("core", "0026_auto_20201222_1833"),
("token", "0005_auto_20210623_1242"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("token", "0006_auto_20210721_1543"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/token/migrations/0008_permission_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
("token", "0007_remove_permission_fields"),
]
Expand Down
1 change: 0 additions & 1 deletion src/objects/utils/migration_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def database_forwards(self, app_label, schema_editor, from_state, to_state) -> N
if router.allow_migrate(
schema_editor.connection.alias, app_label, **self.hints
):

base_sql = _get_reset_sql()

with schema_editor.connection.cursor() as cursor:
Expand Down