question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reflecting table containing only oid column raises NoSuchTableError

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:18 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
zzzeekcommented, Sep 30, 2021

oh yes, that works fine sure. this issue is about reflection

0reactions
sqla-testercommented, Oct 12, 2021

Sumit Khanna has proposed a fix for this issue in the main branch:

Reflect table can reflect table with no columns https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3164

Read more comments on GitHub >

github_iconTop Results From Across the Web

sqlalchemy.exc.NoSuchTableError Example - Program Talk
Several reflection methods require the table id. The idea for using this method is that it can be fetched one time and cached...
Read more >
mssql reflection NoSuchTableError - Google Groups
I am experimenting with SA on MSSQL and am having difficulty with table reflection as outlined in the tutorial, for instance: from sqlalchemy...
Read more >
zzzeek / sqlalchemy_old / issues — Bitbucket
#3247: Reflecting table containing only oid column raises NoSuchTableError ... wrap db table into Table object if the table doesn't contain primary key....
Read more >
0.3 Changelog — SQLAlchemy 2.0 Documentation
columns can be overridden in a reflected table with a “key” attribute different than the column's name, including for primary key columns. References:...
Read more >
https://stuff.mit.edu/afs/sipb/project/bazki/lib/p...
Sequence` construct:: Table('sometable', metadata, Column('id', Integer, ... default, reflection from sqlalchemy.sql import compiler, expression, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found