summaryrefslogtreecommitdiff
path: root/test/engine
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-07-25 12:14:22 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-07-25 12:14:22 -0400
commit6b60d3a9e6ba93d177ac777bfaae8269c18ddee6 (patch)
treed663ca41f3bf05fcfbae2755426469cae5f855f1 /test/engine
parent8560522ff0244c93dab62276f9ba445df90f0d39 (diff)
downloadsqlalchemy-6b60d3a9e6ba93d177ac777bfaae8269c18ddee6.tar.gz
- The MySQL dialect will now disable :meth:`.ConnectionEvents.handle_error`
events from firing for those statements which it uses internally to detect if a table exists or not. This is achieved using an execution option ``skip_user_error_events`` that disables the handle error event for the scope of that execution. In this way, user code that rewrites exceptions doesn't need to worry about the MySQL dialect or other dialects that occasionally need to catch SQLAlchemy specific exceptions.
Diffstat (limited to 'test/engine')
-rw-r--r--test/engine/test_execute.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py
index 33e116cdf..50cf41311 100644
--- a/test/engine/test_execute.py
+++ b/test/engine/test_execute.py
@@ -1659,6 +1659,34 @@ class HandleErrorTest(fixtures.TestBase):
is_(ctx.is_disconnect, False)
is_(ctx.original_exception, nope)
+ def test_exception_event_disable_handlers(self):
+ engine = engines.testing_engine()
+
+ class MyException1(Exception):
+ pass
+
+ @event.listens_for(engine, 'handle_error')
+ def err1(context):
+ stmt = context.statement
+
+ if "ERROR_ONE" in str(stmt):
+ raise MyException1("my exception short circuit")
+
+ with engine.connect() as conn:
+ assert_raises(
+ tsa.exc.DBAPIError,
+ conn.execution_options(
+ skip_user_error_events=True
+ ).execute, "SELECT ERROR_ONE FROM I_DONT_EXIST"
+ )
+
+ assert_raises(
+ MyException1,
+ conn.execution_options(
+ skip_user_error_events=False
+ ).execute, "SELECT ERROR_ONE FROM I_DONT_EXIST"
+ )
+
def _test_alter_disconnect(self, orig_error, evt_value):
engine = engines.testing_engine()