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)
|
self.states.remove(*others)
|
||||||
if state not in already_set:
|
if state not in already_set:
|
||||||
self.states.add(state)
|
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.state_cache = None # invalidate cache
|
||||||
self._cached_state_slug = {}
|
self._cached_state_slug = {}
|
||||||
|
|
||||||
|
|
|
@ -135,15 +135,16 @@ def assertion(statement, state=True, note=None):
|
||||||
else:
|
else:
|
||||||
# build a simulated traceback object
|
# build a simulated traceback object
|
||||||
tb = build_traceback(inspect.stack()[1:])
|
tb = build_traceback(inspect.stack()[1:])
|
||||||
|
e = AssertionError(statement)
|
||||||
# provide extra info if available
|
# provide extra info if available
|
||||||
extra = {}
|
extra = {}
|
||||||
for key in [ 'request', 'status_code', ]:
|
for key in [ 'request', 'status_code', ]:
|
||||||
if key in frame.f_locals:
|
if key in frame.f_locals:
|
||||||
extra[key] = frame.f_locals[key]
|
extra[key] = frame.f_locals[key]
|
||||||
if note:
|
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:
|
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)"):
|
def unreachable(date="(unknown)"):
|
||||||
"Raises an assertion or sends traceback to admins if executed."
|
"Raises an assertion or sends traceback to admins if executed."
|
||||||
|
|
Loading…
Reference in a new issue