Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7066692
D3168.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D3168.diff
View Options
diff --git a/swh/storage/cassandra/storage.py b/swh/storage/cassandra/storage.py
--- a/swh/storage/cassandra/storage.py
+++ b/swh/storage/cassandra/storage.py
@@ -1071,16 +1071,19 @@
if not self._cql_runner.metadata_fetcher_get(**fetcher):
raise StorageArgumentException(f"Unknown fetcher {fetcher}")
- self._cql_runner.origin_metadata_add(
- origin_url,
- authority["type"],
- authority["url"],
- discovery_date,
- fetcher["name"],
- fetcher["version"],
- format,
- metadata,
- )
+ try:
+ self._cql_runner.origin_metadata_add(
+ origin_url,
+ authority["type"],
+ authority["url"],
+ discovery_date,
+ fetcher["name"],
+ fetcher["version"],
+ format,
+ metadata,
+ )
+ except TypeError as e:
+ raise StorageArgumentException(*e.args)
def origin_metadata_get(
self,
diff --git a/swh/storage/db.py b/swh/storage/db.py
--- a/swh/storage/db.py
+++ b/swh/storage/db.py
@@ -1096,8 +1096,7 @@
authority_id, fetcher_id, format, metadata)
SELECT id, %s, %s, %s, %s, %s FROM origin WHERE url = %s"""
cur.execute(
- insert,
- (discovery_date, authority, fetcher, format, jsonize(metadata), origin),
+ insert, (discovery_date, authority, fetcher, format, metadata, origin),
)
def origin_metadata_get(
diff --git a/swh/storage/in_memory.py b/swh/storage/in_memory.py
--- a/swh/storage/in_memory.py
+++ b/swh/storage/in_memory.py
@@ -1059,6 +1059,10 @@
raise StorageArgumentException(
"origin_id must be str, not %r" % (origin_url,)
)
+ if not isinstance(metadata, bytes):
+ raise StorageArgumentException(
+ "metadata must be bytes, not %r" % (metadata,)
+ )
authority_key = self._metadata_authority_key(authority)
if authority_key not in self._metadata_authorities:
raise StorageArgumentException(f"Unknown authority {authority}")
diff --git a/swh/storage/storage.py b/swh/storage/storage.py
--- a/swh/storage/storage.py
+++ b/swh/storage/storage.py
@@ -1255,9 +1255,18 @@
)
if not fetcher_id:
raise StorageArgumentException(f"Unknown fetcher {fetcher}")
- db.origin_metadata_add(
- origin_url, discovery_date, authority_id, fetcher_id, format, metadata, cur
- )
+ try:
+ db.origin_metadata_add(
+ origin_url,
+ discovery_date,
+ authority_id,
+ fetcher_id,
+ format,
+ metadata,
+ cur,
+ )
+ except psycopg2.ProgrammingError as e:
+ raise StorageArgumentException(*e.args)
send_metric("origin_metadata:add", count=1, method_name="origin_metadata_add")
@timed
diff --git a/swh/storage/tests/test_storage.py b/swh/storage/tests/test_storage.py
--- a/swh/storage/tests/test_storage.py
+++ b/swh/storage/tests/test_storage.py
@@ -3225,6 +3225,21 @@
)
)
+ def test_origin_metadata_add_dict(self, swh_storage):
+ origin = data.origin
+ fetcher = data.metadata_fetcher
+ authority = data.metadata_authority
+ swh_storage.origin_add([origin])[0]
+
+ swh_storage.metadata_fetcher_add(**fetcher)
+ swh_storage.metadata_authority_add(**authority)
+
+ kwargs = data.origin_metadata.copy()
+ kwargs["metadata"] = {"foo": "bar"}
+
+ with pytest.raises(StorageArgumentException):
+ swh_storage.origin_metadata_add(**kwargs)
+
def test_origin_metadata_get(self, swh_storage):
authority = data.metadata_authority
fetcher = data.metadata_fetcher
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Nov 5 2024, 6:27 PM (11 w, 14 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3221511
Attached To
D3168: origin_metadata_add: Reject non-bytes types for 'metadata'.
Event Timeline
Log In to Comment