def handle_qserv_exception(context):
    conn = context.connection.connection
    if hasattr(conn, "error") and context.original_exception.args[0] == -1:
        # Handle Qserv Errors where we return error codes above those
        # identified by the MySQLdb driver.
        # The MySQL driver, by default, returns a "whack" error code
        # if this is the case with error == -1.
        from _mysql_exceptions import InterfaceError as MysqlIError
        old_exc = context.sqlalchemy_exception
        orig = MysqlIError(conn.errno(), conn.error())
        return InterfaceError(old_exc.statement, old_exc.params, orig,
                              old_exc.connection_invalidated)
    pass
Beispiel #2
0
    def test_execute_with_session_with_reconnection(self,
                                                    apply_and_flush_mock):
        function_mock = Mock()
        args = ()
        kwargs = {}

        broken_session = Mock()
        new_session = Mock()
        session_class_mock = Mock()
        session_class_mock.side_effect = [broken_session, new_session]

        apply_and_flush_mock.side_effect = [
            InterfaceError(None, None, None, None), sentinel
        ]

        result = db_manager._execute_with_session(session_class_mock,
                                                  function_mock, args, kwargs)

        expected_calls = [
            call(function_mock, broken_session, args, kwargs),
            call(function_mock, new_session, args, kwargs),
        ]
        self.assertEqual(apply_and_flush_mock.call_args_list, expected_calls)
        self.assertEqual(result, sentinel)