Skip to content

Commit 51806b1

Browse files
committed
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
1 parent ac5e88b commit 51806b1

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

ietf/doc/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ def set_state(self, state):
267267
self.states.remove(*others)
268268
if state not in already_set:
269269
self.states.add(state)
270+
if state.type and state.type.slug == 'draft-iesg':
271+
iesg_state = self.states.get(type_id="draft-iesg") # pyflakes:ignore
272+
log.assertion('iesg_state', note="A document's 'draft-iesg' state should never be unset'. Failed for %s"%self.name)
270273
self.state_cache = None # invalidate cache
271274
self._cached_state_slug = {}
272275

ietf/utils/log.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,16 @@ def assertion(statement, state=True, note=None):
135135
else:
136136
# build a simulated traceback object
137137
tb = build_traceback(inspect.stack()[1:])
138+
e = AssertionError(statement)
138139
# provide extra info if available
139140
extra = {}
140141
for key in [ 'request', 'status_code', ]:
141142
if key in frame.f_locals:
142143
extra[key] = frame.f_locals[key]
143144
if note:
144-
logger.error("Assertion failed: '%s': %s != %s (%s)", statement, repr(value), state, note, exc_info=(AssertionError, None, tb), extra=extra)
145+
logger.error("Assertion failed: '%s': %s != %s (%s)", statement, repr(value), state, note, exc_info=(AssertionError, e, tb), extra=extra)
145146
else:
146-
logger.error("Assertion failed: '%s': %s != %s", statement, repr(value), state, exc_info=(AssertionError, None, tb), extra=extra)
147+
logger.error("Assertion failed: '%s': %s != %s", statement, repr(value), state, exc_info=(AssertionError, e, tb), extra=extra)
147148

148149
def unreachable(date="(unknown)"):
149150
"Raises an assertion or sends traceback to admins if executed."

0 commit comments

Comments
 (0)