MagicStack / MagicStack/asyncpg
Invalid OID Handling in SQLAlchemy with asyncpg and autoload_with Causes DataError
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 8.1k
- Forks
- 468
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
- Create a PostgreSQL table with an OID that exceeds the int32 range. For example, an OID like 3195477613.
- 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)
- 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
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
No se indica ningún archivo de origen ni ninguna prueba. Empieza reproduciendo la carga de metadatos de SQLAlchemy Table(..., autoload_with=conn) contra PostgreSQL 14 con asyncpg 0.30.0 y el OID indicado; después, sigue el tratamiento del parámetro OID. Se considera terminado cuando la carga de metadatos tiene éxito para OIDs por encima del rango de int32 sin DataError.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- postgresql, python, sqlalchemy
- Área
- databases
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 38/100