]> 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:17:03 +0000 (22:17 -0400)
Fixes: #7283
Change-Id: I5402a72617b7f9bc366d64bc5ce8669374839984
(cherry picked from commit 9fa79bb53638e02aaa45d77397b39a1b652ba5f1)

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 f8b5dd6062ac75df67b631ffd11bb8b705a93f18..e6f669e4c331c4ec66a40144c78b5d8fd1a636c8 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 22b85f398d92657df546a546fe84f5f6e93b90a6..d62b608095aa5cbe785663992809ded2225b19bf 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 687dadfd1aa47e010c9d2522b93eb280ff754ef7..006c523a69da07ff58766978193dc32ffafb9a4f 100644 (file)
@@ -1269,6 +1269,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