]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: fix overflow in faker datetime handling
authorDylan Young <dylanyoungmeijer@gmail.com>
Wed, 15 Jul 2026 01:22:06 +0000 (22:22 -0300)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 18 Jul 2026 18:51:29 +0000 (20:51 +0200)
Causes at least test_adapt::test_random to fail sometimes.

tests/fix_faker.py

index 905b6ad4a845163950f11b522b036dd73b1a966c..cd6511f7d8330b4f30c36ee7c6e437fce4b0cd24 100644 (file)
@@ -334,10 +334,10 @@ class Faker:
         return self.schema_time(cls)
 
     def make_datetime(self, spec):
-        # Add a day because with timezone we might go BC
+        # Add/subtract a day because with timezone we might overflow
         dtmin = dt.datetime.min + dt.timedelta(days=1)
-        delta = dt.datetime.max - dtmin
-        micros = randrange((delta.days + 1) * 24 * 60 * 60 * 1_000_000)
+        delta = dt.datetime.max - dt.timedelta(days=1) - dtmin
+        micros = randrange(int(delta.total_seconds() * 1_000_000))
         rv = dtmin + dt.timedelta(microseconds=micros)
         if spec[1]:
             rv = rv.replace(tzinfo=self._make_tz(spec))