From 51806b1964b3a85a46bcbeb75724c194824f77b9 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Fri, 18 Sep 2020 14:15:02 +0000 Subject: [PATCH] Updated log.assertion() to provide an exception object (under Py3, it seems that logging.Logger instances ignore the traceback if there isn't also an exception object). Added a check for unset draft-iesg state to Document.set_state(). - Legacy-Id: 18503 --- ietf/doc/models.py | 3 +++ ietf/utils/log.py | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ietf/doc/models.py b/ietf/doc/models.py index d5d78ad66..c1edea716 100644 --- a/ietf/doc/models.py +++ b/ietf/doc/models.py @@ -267,6 +267,9 @@ class DocumentInfo(models.Model): self.states.remove(*others) if state not in already_set: self.states.add(state) + if state.type and state.type.slug == 'draft-iesg': + iesg_state = self.states.get(type_id="draft-iesg") # pyflakes:ignore + log.assertion('iesg_state', note="A document's 'draft-iesg' state should never be unset'. Failed for %s"%self.name) self.state_cache = None # invalidate cache self._cached_state_slug = {} diff --git a/ietf/utils/log.py b/ietf/utils/log.py index b2aca86b8..d5a54e551 100644 --- a/ietf/utils/log.py +++ b/ietf/utils/log.py @@ -135,15 +135,16 @@ def assertion(statement, state=True, note=None): else: # build a simulated traceback object tb = build_traceback(inspect.stack()[1:]) + e = AssertionError(statement) # provide extra info if available extra = {} for key in [ 'request', 'status_code', ]: if key in frame.f_locals: extra[key] = frame.f_locals[key] if note: - logger.error("Assertion failed: '%s': %s != %s (%s)", statement, repr(value), state, note, exc_info=(AssertionError, None, tb), extra=extra) + logger.error("Assertion failed: '%s': %s != %s (%s)", statement, repr(value), state, note, exc_info=(AssertionError, e, tb), extra=extra) else: - logger.error("Assertion failed: '%s': %s != %s", statement, repr(value), state, exc_info=(AssertionError, None, tb), extra=extra) + logger.error("Assertion failed: '%s': %s != %s", statement, repr(value), state, exc_info=(AssertionError, e, tb), extra=extra) def unreachable(date="(unknown)"): "Raises an assertion or sends traceback to admins if executed."