Skip to content

Commit 4549268

Browse files
authored
Merge pull request #407 from maykinmedia/issue/269-correctionfor
fix for correctionFor = null
2 parents 1e57f38 + c0bf5ac commit 4549268

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

src/objects/api/serializers.py

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ObjectRecordSerializer(serializers.ModelSerializer):
1818
source="correct",
1919
slug_field="index",
2020
required=False,
21+
allow_null=True,
2122
help_text=_("Index of the record corrected by the current record"),
2223
)
2324
correctedBy = serializers.SlugRelatedField(

src/objects/api/v1/openapi.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,6 @@ components:
642642
minimum: 0
643643
description: Version of the OBJECTTYPE for data in the object record
644644
data:
645-
type: object
646-
additionalProperties: {}
647645
description: Object data, based on OBJECTTYPE
648646
geometry:
649647
allOf:
@@ -794,8 +792,6 @@ components:
794792
minimum: 0
795793
description: Version of the OBJECTTYPE for data in the object record
796794
data:
797-
type: object
798-
additionalProperties: {}
799795
description: Object data, based on OBJECTTYPE
800796
geometry:
801797
allOf:
@@ -825,6 +821,7 @@ components:
825821
maximum: 2147483647
826822
minimum: 0
827823
description: Index of the record corrected by the current record
824+
nullable: true
828825
correctedBy:
829826
type: integer
830827
maximum: 2147483647

src/objects/api/v2/openapi.yaml

+1-6
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,6 @@ components:
730730
minimum: 0
731731
description: Version of the OBJECTTYPE for data in the object record
732732
data:
733-
type: object
734-
additionalProperties: {}
735733
description: Object data, based on OBJECTTYPE
736734
geometry:
737735
allOf:
@@ -890,8 +888,6 @@ components:
890888
minimum: 0
891889
description: Version of the OBJECTTYPE for data in the object record
892890
data:
893-
type: object
894-
additionalProperties: {}
895891
description: Object data, based on OBJECTTYPE
896892
geometry:
897893
allOf:
@@ -921,6 +917,7 @@ components:
921917
maximum: 2147483647
922918
minimum: 0
923919
description: Index of the record corrected by the current record
920+
nullable: true
924921
correctedBy:
925922
type: integer
926923
maximum: 2147483647
@@ -1044,8 +1041,6 @@ components:
10441041
type: boolean
10451042
description: Use field-based authorization
10461043
fields:
1047-
type: object
1048-
additionalProperties: {}
10491044
nullable: true
10501045
title: Mode
10511046
description: Fields allowed for this token in relation to objecttype versions.

src/objects/tests/v2/test_object_api.py

+39-2
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ def test_history_object(self, m):
327327
],
328328
)
329329

330-
# In the ticket https://github.com/maykinmedia/objects-api/issues/282 we descovered that updating an object \
331-
# where the startAt value has been moddified with an earlier date causes an 500 response.
330+
# In the ticket https://github.com/maykinmedia/objects-api/issues/282 we discovered that updating an object \
331+
# where the startAt value has been modified with an earlier date causes an 500 response.
332332
def test_updating_object_after_changing_the_startAt_value_returns_200(self, m):
333333
mock_service_oas_get(m, OBJECT_TYPES_API, "objecttypes")
334334
m.get(
@@ -388,3 +388,40 @@ def test_updating_object_after_changing_the_startAt_value_returns_200(self, m):
388388
response_updating_data_after_startAt_modification.status_code,
389389
status.HTTP_200_OK,
390390
)
391+
392+
# regression test for https://github.com/maykinmedia/objects-api/issues/268
393+
def test_update_object_correctionFor(self, m):
394+
mock_service_oas_get(m, OBJECT_TYPES_API, "objecttypes")
395+
m.get(
396+
f"{self.object_type.url}/versions/1",
397+
json=mock_objecttype_version(self.object_type.url),
398+
)
399+
m.get(self.object_type.url, json=mock_objecttype(self.object_type.url))
400+
401+
initial_record = ObjectRecordFactory.create(
402+
object__object_type=self.object_type, version=1
403+
)
404+
object = initial_record.object
405+
# correction record
406+
ObjectRecordFactory.create(object=object, version=1, correct=initial_record)
407+
408+
url = reverse("object-detail", args=[object.uuid])
409+
modified_data = {
410+
"type": self.object_type.url,
411+
"record": {
412+
"typeVersion": 1,
413+
"data": {"plantDate": "2020-04-12", "diameter": 30},
414+
"startAt": "2024-01-01",
415+
"correctionFor": None,
416+
},
417+
}
418+
419+
response = self.client.put(url, data=modified_data, **GEO_WRITE_KWARGS)
420+
421+
self.assertEqual(response.status_code, 200)
422+
423+
object.refresh_from_db()
424+
self.assertEqual(object.records.count(), 3)
425+
426+
last_record = object.last_record
427+
self.assertIsNone(last_record.correct)

0 commit comments

Comments
 (0)