MetaData.reflect() should skip tables that can't be DESCRIBE'd (with warning)
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)
-
repo owner -
repo owner - changed milestone to 1.2
-
repo owner -
repo owner - changed status to resolved
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 toDESCRIBE
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>>
- Log in to comment
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.