From: Mike Bayer Date: Tue, 6 Feb 2018 20:47:43 +0000 (-0500) Subject: Check cx_Oracle error code on all exception classes X-Git-Tag: rel_1_2_3~18^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2bc7dfebe6dd708573fcc08b769241b36d675588;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Check cx_Oracle error code on all exception classes Fixed bug in cx_Oracle disconnect detection, used by pre_ping and other features, where an error could be raised as DatabaseError which includes a numeric error code; previously we weren't checking in this case for a disconnect code. Change-Id: I359bb5ede25a4726ea632b81af83c6391f405ae1 Fixes: #4182 --- diff --git a/doc/build/changelog/unreleased_12/4182.rst b/doc/build/changelog/unreleased_12/4182.rst new file mode 100644 index 0000000000..67126b41d3 --- /dev/null +++ b/doc/build/changelog/unreleased_12/4182.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, oracle + :tickets: 4182 + + Fixed bug in cx_Oracle disconnect detection, used by pre_ping and other + features, where an error could be raised as DatabaseError which includes a + numeric error code; previously we weren't checking in this case for a + disconnect code. diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index 24655ee1b1..5f07e869ee 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -817,10 +817,13 @@ class OracleDialect_cx_oracle(OracleDialect): def is_disconnect(self, e, connection, cursor): error, = e.args - if isinstance(e, ( - self.dbapi.InterfaceError, self.dbapi.DatabaseError)): - return "not connected" in str(e) - elif hasattr(error, 'code'): + if isinstance( + e, + (self.dbapi.InterfaceError, self.dbapi.DatabaseError) + ) and "not connected" in str(e): + return True + + if hasattr(error, 'code'): # ORA-00028: your session has been killed # ORA-03114: not connected to ORACLE # ORA-03113: end-of-file on communication channel diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index 5263c79db0..1b79347944 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -1829,7 +1829,8 @@ class HandleErrorTest(fixtures.TestBase): with expect_warnings( r"An exception has occurred during handling of a previous " - r"exception. The previous exception is.*i_dont_exist", + r"exception. The previous exception " + r"is.*(?:i_dont_exist|does not exist)", py2konly=True ): with patch.object(conn.dialect, "do_rollback", boom) as patched: diff --git a/test/requirements.py b/test/requirements.py index d7eaec5fdb..5ae251f9bd 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -1002,7 +1002,7 @@ class DefaultRequirements(SuiteRequirements): @property def ad_hoc_engines(self): - return exclusions.skip_if(["oracle"]) + return exclusions.open() @property def no_mssql_freetds(self):