MetaData.reflect() should skip tables that can't be DESCRIBE'd (with warning)

Issue #3871 resolved
halfak created an issue

I work on databases that are messy. Sometimes views will become out of sync with the underlying database. I'd like to have the option of ignoring these views when employing MetaData.reflect(views=True). Right now, this call errors out when it encounters these types of views.

sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1356, "View 'enwiki_p.aft_article_answer' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them") [SQL: 'DESCRIBE `aft_article_answer`']

Proposed solution

Handle these errors using logging.warn() and skip gathering metadata for these tables.

Alternative solution

Don't change the default behavior, but provide a function parameter to reflect() that would enable the behavior proposed above.

Comments (4)

  1. Mike Bayer repo owner
    • changed component to mysql
    • changed milestone to 1.1.x

    sure, take a look here and we can add this as an additional failure mode. If you'd like to work on a PR (and a functional test in test/dialect/mysql/test_reflection.py even) that would expedite.

  2. Mike Bayer repo owner

    Allow metadata.reflect() to recover from unreflectable tables

    Added support for views that are unreflectable due to stale table definitions, when calling :meth:.MetaData.reflect; a warning is emitted for the table that cannot respond to DESCRIBE but the operation succeeds. The MySQL dialect now raises UnreflectableTableError which is in turn caught by MetaData.reflect(). Reflecting the view standalone raises this error directly.

    Change-Id: Id8005219d8e073c154cc84a873df911b4a6cf4d6 Fixes: #3871

    → <<cset 9f0fb6c60182>>

  3. Log in to comment