Closed
Description
Describe the bug
Inserting infinite value in a float column fails.
11
To Reproduce
import asyncio
from sqlalchemy import Column, Integer, Float
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
Base = declarative_base()
async_engine = create_async_engine(
"postgresql+asyncpg://user:password@localhost:5450/postgres",
echo=True,
)
async_session = sessionmaker(async_engine, expire_on_commit=False, class_=AsyncSession)
class Test(Base):
__tablename__ = "test"
id = Column(Integer, primary_key=True)
data = Column(Float)
async def async_main():
async with async_engine.begin() as conn:
await conn.run_sync(Base.metadata.drop_all)
await conn.run_sync(Base.metadata.create_all)
async with async_session() as session:
test = Test(data=float("inf"))
session.add(test)
await session.commit()
if __name__ == "__main__":
asyncio.run(async_main())
Error
sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class 'asyncpg.exceptions.DataError'>: invalid input for query argument $1: inf (numeric type does not support infinite values)
[SQL: INSERT INTO test (data) VALUES (%s) RETURNING test.id]
[parameters: (inf,)]
Versions
- OS: ubuntu 20.04
- Python: 3.6.10
- SQLAlchemy: 1.4.26
- Database: postgres 9.6.2
- DBAPI (eg: psycopg, cx_oracle, mysqlclient): asyncpg
Additional context
Shameless copy/paste from MagicStack/asyncpg#811
Edit: correct link
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
zzzeek commentedon Nov 2, 2021
i propose this is a driver issue. see #977. have you tried asyncpg directly?
zzzeek commentedon Nov 2, 2021
right here, asyncpg raises this explicitly https://github.com/MagicStack/asyncpg/blob/bc4127f44d3c7fb0e9813cf7deba023569039a93/tests/test_codecs.py#L636
zzzeek commentedon Nov 2, 2021
it's mentioned at MagicStack/asyncpg#811 and they state we'd use 'float" and not "numeric".
ludaavics commentedon Nov 2, 2021
Plain asyncpg seems fine.
Numeric indeed do not support inf, but issue seems to be somewhere along the line asyncpg thinks the columns is numeric, not float?
zzzeek commentedon Nov 2, 2021
did you mean to link to MagicStack/asyncpg#811 ?
sqla-tester commentedon Nov 2, 2021
Mike Bayer has proposed a fix for this issue in the main branch:
map Float to asyncpg.FLOAT, test for infinity https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3260
sqla-tester commentedon Nov 2, 2021
Mike Bayer has proposed a fix for this issue in the rel_1_4 branch:
map Float to asyncpg.FLOAT, test for infinity https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3261
ludaavics commentedon Nov 2, 2021
Ah yes my mistake. Edited
3 remaining items