summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/build/changelog/unreleased_14/7283.rst9
-rw-r--r--lib/sqlalchemy/dialects/postgresql/asyncpg.py9
-rw-r--r--lib/sqlalchemy/testing/requirements.py6
-rw-r--r--lib/sqlalchemy/testing/suite/test_types.py10
-rw-r--r--test/requirements.py8
5 files changed, 42 insertions, 0 deletions
diff --git a/doc/build/changelog/unreleased_14/7283.rst b/doc/build/changelog/unreleased_14/7283.rst
new file mode 100644
index 000000000..0cfd2a491
--- /dev/null
+++ b/doc/build/changelog/unreleased_14/7283.rst
@@ -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.
+
diff --git a/lib/sqlalchemy/dialects/postgresql/asyncpg.py b/lib/sqlalchemy/dialects/postgresql/asyncpg.py
index 3d195e691..913b93159 100644
--- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py
+++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py
@@ -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,
diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py
index 8b385b5d2..08acbd2d2 100644
--- a/lib/sqlalchemy/testing/requirements.py
+++ b/lib/sqlalchemy/testing/requirements.py
@@ -981,6 +981,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
least seven decimal places when using the generic Float type.
diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py
index 93d37d4d5..7438b8bc8 100644
--- a/lib/sqlalchemy/testing/suite/test_types.py
+++ b/lib/sqlalchemy/testing/suite/test_types.py
@@ -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])
diff --git a/test/requirements.py b/test/requirements.py
index 3b77bf672..134ddbdfa 100644
--- a/test/requirements.py
+++ b/test/requirements.py
@@ -1173,6 +1173,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
least seven decimal places when using the generic Float type."""