From 0a15fd6e89804fd0bc4f16f98231b9fcb5371cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gregor=20Jer=C5=A1e?= Date: Thu, 28 Nov 2024 21:02:08 +0100 Subject: [PATCH 1/2] Fix crash in annotation value endpoint when removing the delete markers. --- docs/CHANGELOG.rst | 9 +++++++++ resolwe/flow/models/annotations.py | 6 +++--- resolwe/flow/tests/test_annotations.py | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst index 124f0c663..57fc75b5c 100644 --- a/docs/CHANGELOG.rst +++ b/docs/CHANGELOG.rst @@ -6,6 +6,15 @@ All notable changes to this project are documented in this file. This project adheres to `Semantic Versioning `_. +========== +Unreleased +========== + +Fixed +----- +- Fix ``AnnotationValueViewSet`` crash when removing the delete markers + + =================== 42.0.1 - 2024-11-21 =================== diff --git a/resolwe/flow/models/annotations.py b/resolwe/flow/models/annotations.py index 358df6d75..e80abd131 100644 --- a/resolwe/flow/models/annotations.py +++ b/resolwe/flow/models/annotations.py @@ -517,9 +517,9 @@ def delete_marker(self) -> bool: return self._value is None @property - def value(self) -> str | int | float | datetime.date: - """Get the actual value.""" - return self._value["value"] + def value(self) -> Optional[str | int | float | datetime.date]: + """Get the actual value or None if object is delete marker.""" + return None if self.delete_marker else self._value["value"] @value.setter def value(self, value: str | int | float | datetime.date): diff --git a/resolwe/flow/tests/test_annotations.py b/resolwe/flow/tests/test_annotations.py index 4c6bc7147..e9896f92c 100644 --- a/resolwe/flow/tests/test_annotations.py +++ b/resolwe/flow/tests/test_annotations.py @@ -1270,6 +1270,20 @@ def test_list_filter_values(self): self.assertTrue(response.data[0]["value"], "string") self.assertTrue(response.data[0]["label"], "label string") + # Test delete markers are handled properly. + delete_marker = AnnotationValue.objects.create( + entity=self.annotation_value1.entity, + field=self.annotation_value1.field, + _value=None, + contributor=self.annotation_value1.contributor, + ) + request = factory.get("/", {"entity": self.entity1.pk}, format="json") + force_authenticate(request, self.contributor) + response = self.annotationvalue_viewset(request) + self.assertTrue(response.status_code, status.HTTP_200_OK) + self.assertEqual(len(response.data), 0) + delete_marker.delete() + # Another authenticated request. self.annotation_value2.entity = self.entity1 self.annotation_value2.save() From 6ab94e33313dada26ee1f908463efb3aaaa3d1ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gregor=20Jer=C5=A1e?= Date: Mon, 2 Dec 2024 10:56:46 +0100 Subject: [PATCH 2/2] Prepare release 42.0.2 --- docs/CHANGELOG.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst index 57fc75b5c..8fd542ce2 100644 --- a/docs/CHANGELOG.rst +++ b/docs/CHANGELOG.rst @@ -6,9 +6,9 @@ All notable changes to this project are documented in this file. This project adheres to `Semantic Versioning `_. -========== -Unreleased -========== +=================== +42.0.2 - 2024-12-02 +=================== Fixed -----