diff --git a/swh/storage/db.py b/swh/storage/db.py --- a/swh/storage/db.py +++ b/swh/storage/db.py @@ -610,7 +610,7 @@ FROM origin_visit WHERE origin = %%s AND snapshot_id is not null %s - ORDER BY date, visit DESC + ORDER BY date DESC, visit DESC LIMIT 1 """ % (', '.join(self.origin_visit_get_cols[:-1]), extra_clause) 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 @@ -385,7 +385,7 @@ 'target_type': 'revision', } - self.date_visit2 = datetime.datetime(2015, 1, 1, 23, 0, 0, + self.date_visit2 = datetime.datetime(2017, 1, 1, 23, 0, 0, tzinfo=datetime.timezone.utc) self.occurrence2 = { @@ -394,7 +394,7 @@ 'target_type': 'revision', } - self.date_visit3 = datetime.datetime(2015, 1, 1, 23, 0, 0, + self.date_visit3 = datetime.datetime(2018, 1, 1, 23, 0, 0, tzinfo=datetime.timezone.utc) # template occurrence to be filled in test (cf. revision_log_by)