MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.99k stars 404 forks source link

Not accepting str as value for interval/date columns #1169

Open riwu opened 3 months ago

riwu commented 3 months ago

I am using asyncpg as the driver for SQLAlchemy.

class Table(Base):
    __tablename__ = 'table'
    interval: Mapped[timedelta]

session.add(Table(interval='1 min'))

With the above code, it throws this error: sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class 'asyncpg.exceptions.DataError'>: invalid input for query argument $9: '1 min' ('str' object has no attribute 'days')

However, Postgresql accepts '1 min' as a value to an interval column. Why is asyncpg forbidding str even though Postgresql accepts it in this case?

W0504 commented 2 days ago

and Not accepting str as value for int

class Table(Base):
    __tablename__ = 'table'
    num: Mapped[int]

session.add(Table(num='111'))
session.commit()

it throws this error:

<class 'asyncpg.exceptions.DataError'>  ('str' object cannot be interpreted as an integer)