From 9f0fb6c601829cb7c9f449d57e12e8b95dab51f5 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 22 May 2017 14:08:55 -0400 Subject: 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 --- lib/sqlalchemy/testing/assertions.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib/sqlalchemy/testing/assertions.py') diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py index 884556345..dfea33dc7 100644 --- a/lib/sqlalchemy/testing/assertions.py +++ b/lib/sqlalchemy/testing/assertions.py @@ -130,9 +130,16 @@ def _expect_warnings(exc_cls, messages, regex=True, assert_=True, real_warn = warnings.warn - def our_warn(msg, exception, *arg, **kw): - if not issubclass(exception, exc_cls): - return real_warn(msg, exception, *arg, **kw) + def our_warn(msg, *arg, **kw): + if isinstance(msg, exc_cls): + exception = msg + msg = str(exception) + elif arg: + exception = arg[0] + else: + exception = None + if not exception or not issubclass(exception, exc_cls): + return real_warn(msg, *arg, **kw) if not filters: return @@ -143,7 +150,7 @@ def _expect_warnings(exc_cls, messages, regex=True, assert_=True, seen.discard(filter_) break else: - real_warn(msg, exception, *arg, **kw) + real_warn(msg, *arg, **kw) with mock.patch("warnings.warn", our_warn): yield -- cgit v1.2.1