Page MenuHomeSoftware Heritage

D3149.diff
No OneTemporary

D3149.diff

diff --git a/swh/journal/serializers.py b/swh/journal/serializers.py
--- a/swh/journal/serializers.py
+++ b/swh/journal/serializers.py
@@ -49,6 +49,7 @@
def object_key(object_type: str, object_) -> KeyType:
+ object_type = object_type.split(":", 1)[0]
if object_type in ("revision", "release", "directory", "snapshot"):
return object_.id
elif object_type == "content":
diff --git a/swh/journal/tests/test_serializers.py b/swh/journal/tests/test_serializers.py
--- a/swh/journal/tests/test_serializers.py
+++ b/swh/journal/tests/test_serializers.py
@@ -8,6 +8,8 @@
from collections import OrderedDict
from typing import Iterable
+import pytest
+
from swh.journal import serializers
from .conftest import TEST_OBJECTS
@@ -35,7 +37,15 @@
"""Test whether get_key works on all our objects"""
for object_type, objects in TEST_OBJECTS.items():
for obj in objects:
- assert serializers.object_key(object_type, obj) is not None
+ key = serializers.object_key(object_type, obj)
+ assert key is not None
+ # also test "flags" are ignored
+ assert key == serializers.object_key(f"{object_type}:", obj)
+ assert key == serializers.object_key(f"{object_type}:toto", obj)
+ assert key == serializers.object_key(f"{object_type}:toto:tutu", obj)
+
+ with pytest.raises(ValueError):
+ serializers.object_key(f"{object_type};toto", obj)
def test_pprint_key():

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 30, 1:46 PM (8 h, 35 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3221825

Event Timeline