sqlalchemy: Reflecting table containing only oid column raises NoSuchTableError
Migrated issue, originally created by Ulrich Petri (@ulope)
I ran into what I think is a bug while trying to reflect a legacy database that contained a table with no columns except for the Postgres oid column (don’t ask why…). That table had been created with the “WITH OIDS” option.
When using reflection on a table like this a NoSuchTable
exception is raised.
The reason for that lies in sqlalchemy.engine.reflection.reflecttable
. The found_table
flag is set to true inside the column processing loop. This loop is not executed in my case because sqlalchemy.dialects.postgresql.base.PGDialect.get_columns
excludes attributes with an attnum
< 1 (attnum
for the oid
column is -2) returning an empty list in this case.
I’m aware that this is a very unusual case. But I’d argue that at least the exception is misleading and should be changed since the table clearly exists.
Minimal example:
createdb test
psql test <<EOF
create table test () with oids;
EOF
from sqlalchemy import create_engine, MetaData
engine = create_engine("postgresql+psycopg2://localhost/test")
meta = MetaData()
meta.reflect(bind=engine)
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 18 (7 by maintainers)
oh yes, that works fine sure. this issue is about reflection