]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
map Float to asyncpg.FLOAT, test for infinity
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 2 Nov 2021 22:19:35 +0000 (18:19 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 3 Nov 2021 02:16:54 +0000 (22:16 -0400)
Fixes: #7283
Change-Id: I5402a72617b7f9bc366d64bc5ce8669374839984

doc/build/changelog/unreleased_14/7283.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/postgresql/asyncpg.py
lib/sqlalchemy/testing/requirements.py
lib/sqlalchemy/testing/suite/test_types.py
test/requirements.py

diff --git a/doc/build/changelog/unreleased_14/7283.rst b/doc/build/changelog/unreleased_14/7283.rst
new file mode 100644 (file)
index 0000000..0cfd2a4
--- /dev/null
@@ -0,0 +1,9 @@
+.. change::
+    :tags: bug, postgresql
+    :tickets: 7283
+
+    Changed the asyncpg dialect to bind the :class:`.Float` type to the "float"
+    PostgreSQL type instead of "numeric" so that the value ``float(inf)`` can
+    be accommodated. Added test suite support for persisence of the "inf"
+    value.
+
index 3d195e691ae9b1aaf688ba4843d63b816c98c9a8..913b9315974592edda23bb622c34ab5aec7396bb 100644 (file)
@@ -249,6 +249,9 @@ class AsyncpgUUID(UUID):
 
 
 class AsyncpgNumeric(sqltypes.Numeric):
+    def get_dbapi_type(self, dbapi):
+        return dbapi.NUMBER
+
     def bind_processor(self, dialect):
         return None
 
@@ -277,6 +280,11 @@ class AsyncpgNumeric(sqltypes.Numeric):
                 )
 
 
+class AsyncpgFloat(AsyncpgNumeric):
+    def get_dbapi_type(self, dbapi):
+        return dbapi.FLOAT
+
+
 class AsyncpgREGCLASS(REGCLASS):
     def get_dbapi_type(self, dbapi):
         return dbapi.STRING
@@ -883,6 +891,7 @@ class PGDialect_asyncpg(PGDialect):
             sqltypes.Integer: AsyncpgInteger,
             sqltypes.BigInteger: AsyncpgBigInteger,
             sqltypes.Numeric: AsyncpgNumeric,
+            sqltypes.Float: AsyncpgFloat,
             sqltypes.JSON: AsyncpgJSON,
             json.JSONB: AsyncpgJSONB,
             sqltypes.JSON.JSONPathType: AsyncpgJSONPathType,
index 8b385b5d2dfc1db67502266f06cd16da472a0eb6..08acbd2d2d1bd25907e170d5f84e6cfc40dbafb2 100644 (file)
@@ -980,6 +980,12 @@ class SuiteRequirements(Requirements):
 
         return exclusions.closed()
 
+    @property
+    def infinity_floats(self):
+        """The Float type can persist and load float('inf'), float('-inf')."""
+
+        return exclusions.closed()
+
     @property
     def precision_generic_float_type(self):
         """target backend will return native floating point numbers with at
index 93d37d4d50be143e8ee0292144f76abe9566f284..7438b8bc89313ef268c670eb5ec3a4fcd681b6ac 100644 (file)
@@ -590,6 +590,16 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase):
             [15.7563],
         )
 
+    @testing.requires.infinity_floats
+    def test_infinity_floats(self, do_numeric_test):
+        """test for #977, #7283"""
+
+        do_numeric_test(
+            Float(None),
+            [float("inf")],
+            [float("inf")],
+        )
+
     @testing.requires.fetch_null_from_numeric
     def test_numeric_null_as_decimal(self, do_numeric_test):
         do_numeric_test(Numeric(precision=8, scale=4), [None], [None])
index 3b77bf6721b94ccd6d816152c2b86f5c5a6f1a13..134ddbdfa4d3ff298b7696d8e55d1c398594b7cb 100644 (file)
@@ -1172,6 +1172,14 @@ class DefaultRequirements(SuiteRequirements):
             ]
         )
 
+    @property
+    def infinity_floats(self):
+        return fails_on_everything_except(
+            "sqlite", "postgresql+psycopg2", "postgresql+asyncpg"
+        ) + skip_if(
+            "postgresql+pg8000", "seems to work on pg14 only, not earlier?"
+        )
+
     @property
     def precision_generic_float_type(self):
         """target backend will return native floating point numbers with at