Skip to content

Commit

Permalink
Support annotation metadata in annotation PATCH-ing
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Oct 5, 2023
1 parent be708d4 commit 5581bd3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions h/schemas/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ def validate(self, data):
new_appstruct.get("target_uri", self.existing_target_uri),
)

new_appstruct["metadata"] = appstruct.pop("metadata", None)

new_appstruct["extra"] = appstruct

return new_appstruct
Expand Down
5 changes: 4 additions & 1 deletion h/services/annotation_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def update_annotation(
"""
initial_target_uri = annotation.target_uri

annotation_metadata = data.pop("metadata", None)
self._update_annotation_values(annotation, data)
if update_timestamp:
annotation.updated = datetime.utcnow()
Expand All @@ -132,9 +133,11 @@ def update_annotation(
document.get("document_uri_dicts", {}),
updated=annotation.updated,
)

self.upsert_annotation_slim(annotation)

if annotation_metadata:
self._annotation_metadata_service.set(annotation, annotation_metadata)

# The search index service by default does not reindex if the existing ES
# entry's timestamp matches the DB timestamp. If we're not changing this
# timestamp, we need to force reindexing.
Expand Down
14 changes: 14 additions & 0 deletions tests/h/services/annotation_write_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ def test_update_annotation_with_non_defaults(self, svc, annotation, search_index
)
assert result.updated == then

def test_update_annotation_with_metadata(
self, svc, annotation, annotation_metadata_service
):
result = svc.update_annotation(
annotation,
{"metadata": sentinel.metadata},
update_timestamp=False,
reindex_tag="custom_tag",
)

annotation_metadata_service.set.assert_called_once_with(
result, sentinel.metadata
)

def test__validate_group_with_no_group(self, svc, annotation):
annotation.group = None

Expand Down

0 comments on commit 5581bd3

Please sign in to comment.