Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
riwu opened this issue Jul 25, 2024 · 1 comment
Open

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

riwu opened this issue Jul 25, 2024 · 1 comment

Comments

@riwu
Copy link

riwu commented Jul 25, 2024

  • asyncpg version: 0.29.0
  • PostgreSQL version: 15.7
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : local
  • Python version: 3.11
  • Platform: Windows
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: Yes
  • If you built asyncpg locally, which version of Cython did you use?: N/A
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : yes

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
Copy link

W0504 commented Nov 8, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants