Page MenuHomeSoftware Heritage

D3322.diff
No OneTemporary

D3322.diff

diff --git a/swh/storage/algos/snapshot.py b/swh/storage/algos/snapshot.py
--- a/swh/storage/algos/snapshot.py
+++ b/swh/storage/algos/snapshot.py
@@ -87,8 +87,9 @@
snapshot = storage.snapshot_get_branches(
snapshot_id, branches_count=branches_count
)
+ if snapshot is None:
+ return None
snapshot.pop("next_branch")
else:
snapshot = snapshot_get_all_branches(storage, snapshot_id)
-
- return Snapshot.from_dict(snapshot)
+ return Snapshot.from_dict(snapshot) if snapshot else None
diff --git a/swh/storage/tests/algos/test_snapshot.py b/swh/storage/tests/algos/test_snapshot.py
--- a/swh/storage/tests/algos/test_snapshot.py
+++ b/swh/storage/tests/algos/test_snapshot.py
@@ -53,9 +53,10 @@
yield no result
"""
+ # unknown origin so None
assert snapshot_get_latest(swh_storage, "unknown-origin") is None
- # no snapshot on origin visit then nothing is found
+ # no snapshot on origin visit so None
origin = Origin.from_dict(data.origin)
swh_storage.origin_add_one(origin)
swh_storage.origin_visit_add(
@@ -71,6 +72,28 @@
)
assert snapshot_get_latest(swh_storage, origin.url) is None
+ ov1 = swh_storage.origin_visit_get_latest(origin.url)
+ assert ov1 is not None
+ visit_id = ov1["visit"]
+
+ # visit references a snapshot but the snapshot does not exist in backend for some
+ # reason
+ complete_snapshot = Snapshot.from_dict(data.complete_snapshot)
+ swh_storage.origin_visit_status_add(
+ [
+ OriginVisitStatus(
+ origin=origin.url,
+ visit=visit_id,
+ date=data.date_visit2,
+ status="partial",
+ snapshot=complete_snapshot.id,
+ )
+ ]
+ )
+ # so we do not find it
+ assert snapshot_get_latest(swh_storage, origin.url) is None
+ assert snapshot_get_latest(swh_storage, origin.url, branches_count=1) is None
+
def test_snapshot_get_latest(swh_storage):
origin = Origin.from_dict(data.origin)

File Metadata

Mime Type
text/plain
Expires
Dec 21 2024, 9:22 PM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3220059

Event Timeline