Skip to content

Commit

Permalink
Fix crash in annotation value endpoint
Browse files Browse the repository at this point in the history
when removing the delete markers.
  • Loading branch information
gregorjerse committed Nov 29, 2024
1 parent ed41eab commit aec76d0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ Added
-----
- Expose ``status`` on ``collection`` and ``entity`` viewset and allow
filtering and sorting by it

Changed
-------
- Make processing container startup script ``Python`` 3.12 compatible

Fixed
-----
- Fix ``AnnotationValueViewSet`` crash when removing the delete markers


===================
42.0.1 - 2024-11-21
Expand Down
6 changes: 3 additions & 3 deletions resolwe/flow/models/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions resolwe/flow/tests/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit aec76d0

Please sign in to comment.