diff --git a/requirements.txt b/requirements.txt --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ flask iso8601 mypy_extensions -psycopg2 +psycopg2 >= 2.9.0 # v2.9.0 fixes truncation of non-integer timezones redis tenacity >= 6.2 typing-extensions diff --git a/swh/storage/tests/storage_tests.py b/swh/storage/tests/storage_tests.py --- a/swh/storage/tests/storage_tests.py +++ b/swh/storage/tests/storage_tests.py @@ -37,6 +37,8 @@ Snapshot, SnapshotBranch, TargetType, + Timestamp, + TimestampWithTimezone, ) from swh.model.swhids import CoreSWHID, ObjectType from swh.storage import get_storage @@ -1017,6 +1019,35 @@ ("revision", revision2), ] + def test_revision_add_fractional_timezone(self, swh_storage, sample_data): + # When reading a date from this time period, postgresql returns them + # with UTC+00:09:21 as timezone, but psycopg2 < 2.9.0 had to truncate them. + # https://www.psycopg.org/docs/usage.html#time-zones-handling + # + # Therefore, this test fails with psycopg2 < 2.9.0. + revision = attr.evolve( + sample_data.revision, + date=TimestampWithTimezone( + timestamp=Timestamp(seconds=-1855958962, microseconds=0), + offset=0, + negative_utc=False, + ), + ) + init_missing = swh_storage.revision_missing([revision.id]) + assert list(init_missing) == [revision.id] + + actual_result = swh_storage.revision_add([revision]) + assert actual_result == {"revision:add": 1} + + end_missing = swh_storage.revision_missing([revision.id]) + assert list(end_missing) == [] + + assert list(swh_storage.journal_writer.journal.objects) == [ + ("revision", revision) + ] + + assert swh_storage.revision_get([revision.id])[0] == revision + def test_revision_add_name_clash(self, swh_storage, sample_data): revision, revision2 = sample_data.revisions[:2]