summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2023-04-17 14:05:43 +0000
committerGerrit Code Review <review@openstack.org>2023-04-17 14:05:43 +0000
commitf67df4a1663521a423d1054a24ebc7e634b52ed6 (patch)
treef5e503d573713526ee51638b90d25e7d2be2f25f
parent50a1d90e540a942b5ebfeb11a304c78beeadda71 (diff)
parent7d62b3664e4acad9161d849a111bdb8b4d707f61 (diff)
downloadoslo-db-f67df4a1663521a423d1054a24ebc7e634b52ed6.tar.gz
Merge "Match exceptions with multiple lines"
-rw-r--r--oslo_db/sqlalchemy/exc_filters.py89
1 files changed, 45 insertions, 44 deletions
diff --git a/oslo_db/sqlalchemy/exc_filters.py b/oslo_db/sqlalchemy/exc_filters.py
index 420b5c7..4ad7721 100644
--- a/oslo_db/sqlalchemy/exc_filters.py
+++ b/oslo_db/sqlalchemy/exc_filters.py
@@ -44,7 +44,7 @@ def filters(dbname, exception_type, regex):
"""
def _receive(fn):
_registry[dbname][exception_type].extend(
- (fn, re.compile(reg))
+ (fn, re.compile(reg, re.DOTALL))
for reg in
((regex,) if not isinstance(regex, tuple) else regex)
)
@@ -432,50 +432,51 @@ def handler(context):
dialect = compat.dialect_from_exception_context(context)
for per_dialect in _dialect_registries(dialect):
- for exc in (
- context.sqlalchemy_exception,
- context.original_exception):
+ for exc in (context.sqlalchemy_exception, context.original_exception):
for super_ in exc.__class__.__mro__:
- if super_ in per_dialect:
- regexp_reg = per_dialect[super_]
- for fn, regexp in regexp_reg:
- match = regexp.match(exc.args[0])
- if match:
- try:
- fn(
- exc,
- match,
- dialect.name,
- context.is_disconnect)
- except exception.DBError as dbe:
- if (
- context.connection is not None and
- not context.connection.closed and
- not context.connection.invalidated and
- ROLLBACK_CAUSE_KEY
- in context.connection.info
- ):
- dbe.cause = \
- context.connection.info.pop(
- ROLLBACK_CAUSE_KEY)
-
- if isinstance(
- dbe, exception.DBConnectionError):
- context.is_disconnect = True
-
- # new in 2.0.5
- if (
- hasattr(context, "is_pre_ping") and
- context.is_pre_ping
- ):
- # if this is a pre-ping, need to
- # integrate with the built
- # in pre-ping handler that doesnt know
- # about DBConnectionError, just needs
- # the updated status
- return None
-
- return dbe
+ if super_ not in per_dialect:
+ continue
+
+ regexp_reg = per_dialect[super_]
+ for fn, regexp in regexp_reg:
+ match = regexp.match(exc.args[0])
+ if not match:
+ continue
+
+ try:
+ fn(
+ exc,
+ match,
+ dialect.name,
+ context.is_disconnect,
+ )
+ except exception.DBError as dbe:
+ if (
+ context.connection is not None and
+ not context.connection.closed and
+ not context.connection.invalidated and
+ ROLLBACK_CAUSE_KEY in context.connection.info
+ ):
+ dbe.cause = context.connection.info.pop(
+ ROLLBACK_CAUSE_KEY,
+ )
+
+ if isinstance(dbe, exception.DBConnectionError):
+ context.is_disconnect = True
+
+ # new in 2.0.5
+ if (
+ hasattr(context, "is_pre_ping") and
+ context.is_pre_ping
+ ):
+ # if this is a pre-ping, need to
+ # integrate with the built
+ # in pre-ping handler that doesnt know
+ # about DBConnectionError, just needs
+ # the updated status
+ return None
+
+ return dbe
def register_engine(engine):