From 39346d925fd4ede3df2e2fa0abab58811d6f3549 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Tue, 27 Jan 2026 14:24:57 +0100 Subject: [PATCH 1/3] :recycle: [#564] Remove linkableToZaken field from objecttype model this field was introduced in Objecttypes 3.4.0, but removed in 3.4.1 --- docs/manual/migration.rst | 5 +++++ .../management/commands/import_objecttypes.py | 7 +++++-- .../0038_remove_objecttype_linkable_to_zaken.py | 17 +++++++++++++++++ src/objects/core/models.py | 11 ----------- src/objects/tests/utils.py | 3 ++- 5 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 src/objects/core/migrations/0038_remove_objecttype_linkable_to_zaken.py diff --git a/docs/manual/migration.rst b/docs/manual/migration.rst index 0df78046..074a3c05 100644 --- a/docs/manual/migration.rst +++ b/docs/manual/migration.rst @@ -11,6 +11,11 @@ Before updating to 4.0.0 all objecttypes from the ObjectTypes API instance need This command will fetch all objecttypes and their versions from an objecttype service based on its identifier/slug (which can be found in the admin interface under ``Configuration > Services``) and update existing objecttypes or create new ones if they have not been added to the objecttypes API. +.. note:: + + The minimum version of the Objecttypes API application required for this command is + 3.4.0 + .. code-block:: bash src/manage.py import_objecttypes objecttypes-api diff --git a/src/objects/core/management/commands/import_objecttypes.py b/src/objects/core/management/commands/import_objecttypes.py index d9929a79..63840944 100644 --- a/src/objects/core/management/commands/import_objecttypes.py +++ b/src/objects/core/management/commands/import_objecttypes.py @@ -12,7 +12,9 @@ from objects.core.models import ObjectType, ObjectTypeVersion from objects.utils.client import get_objecttypes_client -MIN_OBJECTTYPES_VERSION = "3.4.0" # added boolean field linkable_to_zaken to ObjectType +# Minimum Objecttypes application version is 3.4.0, because that version added the +# version header to the responses +MIN_OBJECTTYPES_VERSION = "2.2.2" class Command(BaseCommand): @@ -101,7 +103,6 @@ def _bulk_create_or_update_objecttypes(self, data): "created_at", "modified_at", "allow_geometry", - "linkable_to_zaken", ], ) @@ -129,6 +130,8 @@ def _parse_objecttype_data( for objecttype in objecttypes: objecttype.pop("versions") objecttype.pop("url") + # This attribute was added in 3.4.0 but removed in 3.4.1 + objecttype.pop("linkableToZaken", None) objecttype["service"] = service objecttype["is_imported"] = True data.append(ObjectType(**underscoreize(objecttype))) diff --git a/src/objects/core/migrations/0038_remove_objecttype_linkable_to_zaken.py b/src/objects/core/migrations/0038_remove_objecttype_linkable_to_zaken.py new file mode 100644 index 00000000..befe537e --- /dev/null +++ b/src/objects/core/migrations/0038_remove_objecttype_linkable_to_zaken.py @@ -0,0 +1,17 @@ +# Generated by Django 5.2.8 on 2026-01-27 13:01 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0037_reference'), + ] + + operations = [ + migrations.RemoveField( + model_name='objecttype', + name='linkable_to_zaken', + ), + ] diff --git a/src/objects/core/models.py b/src/objects/core/models.py index 810181bb..013a3501 100644 --- a/src/objects/core/models.py +++ b/src/objects/core/models.py @@ -155,17 +155,6 @@ class ObjectType(models.Model): "`geometry` property will raise an error " ), ) - linkable_to_zaken = models.BooleanField( - _("linkable to zaken"), - default=False, - help_text=_( - # TODO Document: how and where these links should be created/maintained - "Objects of this type can have a link to 1 or more Zaken.\n" - "True indicates the lifetime of the object is linked to the lifetime " - "of linked zaken, i.e., when all linked Zaken to an object are " - "archived/destroyed, the object will also be archived/destroyed." - ), - ) objects = ObjectTypeQuerySet.as_manager() diff --git a/src/objects/tests/utils.py b/src/objects/tests/utils.py index 1ea4ae4e..9b064fa9 100644 --- a/src/objects/tests/utils.py +++ b/src/objects/tests/utils.py @@ -77,7 +77,6 @@ def mock_objecttypes(uuid1, uuid2): "providerOrganization": "", "documentationUrl": "", "labels": {}, - "linkableToZaken": False, "createdAt": "2020-12-01", "modifiedAt": "2020-12-01", "allowGeometry": True, @@ -102,6 +101,8 @@ def mock_objecttypes(uuid1, uuid2): "providerOrganization": "", "documentationUrl": "", "labels": {}, + # command should be able to handle Objecttypes 3.4.0, which includes + # this attribute "linkableToZaken": False, "createdAt": "2020-12-01", "modifiedAt": "2020-12-01", From f7bcdb77fdacc9d2c21fc267c366eec1b2469fc6 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Tue, 27 Jan 2026 14:25:13 +0100 Subject: [PATCH 2/3] :white_check_mark: [#564] Fix tests for objecttypes import command --- src/objects/core/tests/test_import_objecttypes.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/objects/core/tests/test_import_objecttypes.py b/src/objects/core/tests/test_import_objecttypes.py index 4f1a6653..dbb5a9b9 100644 --- a/src/objects/core/tests/test_import_objecttypes.py +++ b/src/objects/core/tests/test_import_objecttypes.py @@ -35,15 +35,15 @@ def test_api_version_is_required(self): self.m.head(self.url, status_code=200) with self.assertRaisesMessage( - CommandError, "API version must be 3.4.0 or higher" + CommandError, "API version must be 2.2.2 or higher" ): self._call_command() def test_api_version_must_be_greater_than_constant(self): - self.m.head(self.url, status_code=200, headers={"api-version": "3.2.0"}) + self.m.head(self.url, status_code=200, headers={"api-version": "2.1.0"}) with self.assertRaisesMessage( - CommandError, "API version must be 3.4.0 or higher" + CommandError, "API version must be 2.2.2 or higher" ): self._call_command() @@ -88,7 +88,6 @@ def test_new_objecttypes_are_created(self): self.assertEqual(objecttype.provider_organization, "") self.assertEqual(objecttype.documentation_url, "") self.assertEqual(objecttype.labels, {}) - self.assertEqual(objecttype.linkable_to_zaken, False) self.assertEqual(str(objecttype.created_at), "2020-12-01") self.assertEqual(str(objecttype.modified_at), "2020-12-01") self.assertEqual(objecttype.allow_geometry, True) From aca14935ecd645eee211a1aec352c3c029d5ddab Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Tue, 27 Jan 2026 14:53:09 +0100 Subject: [PATCH 3/3] :recycle: [#564] Ensure ObjectType._name is also set via import command --- src/objects/core/management/commands/import_objecttypes.py | 2 ++ src/objects/core/models.py | 2 +- src/objects/core/tests/factories.py | 2 +- src/objects/core/tests/test_import_objecttypes.py | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/objects/core/management/commands/import_objecttypes.py b/src/objects/core/management/commands/import_objecttypes.py index 63840944..f12b4dba 100644 --- a/src/objects/core/management/commands/import_objecttypes.py +++ b/src/objects/core/management/commands/import_objecttypes.py @@ -87,6 +87,7 @@ def _bulk_create_or_update_objecttypes(self, data): ], # TODO remove service from unique_fields after objecttype migration since it will no longer be part of the ObjectType model. update_fields=[ "is_imported", + "_name", "name", "name_plural", "description", @@ -134,6 +135,7 @@ def _parse_objecttype_data( objecttype.pop("linkableToZaken", None) objecttype["service"] = service objecttype["is_imported"] = True + objecttype["_name"] = objecttype["name"] data.append(ObjectType(**underscoreize(objecttype))) return data diff --git a/src/objects/core/models.py b/src/objects/core/models.py index 013a3501..d550e960 100644 --- a/src/objects/core/models.py +++ b/src/objects/core/models.py @@ -162,7 +162,7 @@ class Meta: unique_together = ("service", "uuid") def __str__(self): - return f"{self.service.label}: {self._name}" + return f"{self.service.label}: {self.name or self._name}" @property def url(self): diff --git a/src/objects/core/tests/factories.py b/src/objects/core/tests/factories.py index 9c9d5759..0dff91a4 100644 --- a/src/objects/core/tests/factories.py +++ b/src/objects/core/tests/factories.py @@ -16,9 +16,9 @@ class ObjectTypeFactory(factory.django.DjangoModelFactory[ObjectType]): service = factory.SubFactory(ServiceFactory) uuid = factory.LazyFunction(uuid.uuid4) - _name = factory.Faker("word") name = factory.Faker("word") + _name = factory.LazyAttribute(lambda x: x.name) name_plural = factory.LazyAttribute(lambda x: f"{x.name}s") description = factory.Faker("bs") diff --git a/src/objects/core/tests/test_import_objecttypes.py b/src/objects/core/tests/test_import_objecttypes.py index dbb5a9b9..faf741a7 100644 --- a/src/objects/core/tests/test_import_objecttypes.py +++ b/src/objects/core/tests/test_import_objecttypes.py @@ -76,6 +76,7 @@ def test_new_objecttypes_are_created(self): objecttype = ObjectType.objects.get(uuid=uuid1) self.assertEqual(objecttype.is_imported, True) self.assertEqual(objecttype.name, "Melding") + self.assertEqual(objecttype._name, "Melding") self.assertEqual(objecttype.name_plural, "Meldingen") self.assertEqual(objecttype.description, "") self.assertEqual(objecttype.data_classification, "intern") @@ -139,6 +140,7 @@ def test_existing_objecttypes_are_updated(self): objecttype = ObjectType.objects.get(uuid=objecttype1.uuid) self.assertEqual(objecttype.is_imported, True) self.assertEqual(objecttype.name, "Melding") + self.assertEqual(objecttype._name, "Melding") version = ObjectTypeVersion.objects.get(object_type=objecttype, version=1) self.assertEqual(