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
This commit is contained in:
parent
ac5e88b82b
commit
51806b1964
|
@ -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 = {}
|
||||
|
||||
|
|
|
@ -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."
|
||||
|
|
Loading…
Reference in a new issue