[Sqlalchemy-tickets] Issue #3247: Reflecting table containing only oid column raises NoSuchTableErr
Brought to you by:
zzzeek
|
From: Ulrich P. <iss...@bi...> - 2014-11-11 14:07:29
|
New issue 3247: Reflecting table containing only oid column raises NoSuchTableError https://bitbucket.org/zzzeek/sqlalchemy/issue/3247/reflecting-table-containing-only-oid Ulrich Petri: 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: ``` #!bash createdb test psql test <<EOF create table test () with oids; EOF ``` ``` #!python from sqlalchemy import create_engine, MetaData engine = create_engine("postgresql+psycopg2://localhost/test") meta = MetaData() meta.reflect(bind=engine) ``` |