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

Invalid OID Handling in SQLAlchemy with asyncpg and autoload_with Causes DataError #1212

Open
gtolarc opened this issue Dec 2, 2024 · 0 comments

Comments

@gtolarc
Copy link

gtolarc commented Dec 2, 2024

Describe the bug

I encountered an issue when using SQLAlchemy with asyncpg and the autoload_with option while trying to load table metadata. The problem occurs because PostgreSQL's oid type is treated as a signed 32-bit integer (int32) by asyncpg, which leads to a DataError when the OID value exceeds the maximum range of int32 (2,147,483,647).

Steps to Reproduce

  1. Create a PostgreSQL table with an OID that exceeds the int32 range. For example, an OID like 3195477613.
  2. Use SQLAlchemy to define the table with autoload_with to load metadata:
from sqlalchemy import Table, MetaData

metadata = MetaData()
table = Table("master_product_view", metadata, autoload_with=conn)
  1. Execute the code.

Observed Behavior

The following exception is raised during metadata loading:

sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class 'asyncpg.exceptions.DataError'>: invalid input for query argument $1: 3195477613 (value out of int32 range)

Expected Behavior

The autoload_with option should correctly handle OID values, even if they exceed the int32 range.

asyncpg/SQLAlchemy Version in Use

asyncpg 0.30.0
sqlalchemy 1.4.54

Database Vendor and Major Version

PostgreSQL 14

Python Version

3.13

Operating system

Linux

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

1 participant