From: Daniele Varrazzo Date: Tue, 19 Sep 2023 19:07:20 +0000 (+0200) Subject: fix(c): fix loading of intervals with days and months or years X-Git-Tag: pool-3.1.8~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9efef9f47a77c88eda52d959436716c5b6718f09;p=thirdparty%2Fpsycopg.git fix(c): fix loading of intervals with days and months or years Close #643. --- diff --git a/docs/news.rst b/docs/news.rst index f8e4834df..63290f460 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -16,6 +16,7 @@ Psycopg 3.1.11 (unreleased) - Avoid caching the parsing results of large queries to avoid excessive memory usage (:ticket:`#628`). - Fix integer overflow in C/binary extension with OID > 2^31 (:ticket:`#630`). +- Fix loading of intervals with days and months or years (:ticket:`#643`). - Fix building on Solaris and derivatives (:ticket:`#632`). - Fix possible lack of critical section guard in async `~AsyncCursor.executemany()`. diff --git a/psycopg_c/psycopg_c/types/datetime.pyx b/psycopg_c/psycopg_c/types/datetime.pyx index 3b6fd1f18..1dd859816 100644 --- a/psycopg_c/psycopg_c/types/datetime.pyx +++ b/psycopg_c/psycopg_c/types/datetime.pyx @@ -879,11 +879,11 @@ cdef class IntervalLoader(CLoader): val = -val if ptr[1] == b'y': - days = 365 * val + days += 365 * val elif ptr[1] == b'm': - days = 30 * val + days += 30 * val elif ptr[1] == b'd': - days = val + days += val else: s = bytes(data).decode("utf8", "replace") raise e.DataError(f"can't parse interval {s!r}") diff --git a/tests/types/test_datetime.py b/tests/types/test_datetime.py index 11fe4932c..c89d364d9 100644 --- a/tests/types/test_datetime.py +++ b/tests/types/test_datetime.py @@ -688,6 +688,8 @@ class TestInterval: ("-30d", "-1 month"), ("60d", "2 month"), ("-90d", "-3 month"), + ("186d", "6 mons 6 days"), + ("736d", "2 years 6 days"), ], ) @pytest.mark.parametrize("fmt_out", pq.Format)