'Return True and print an ugly error on transaction violation.
This code is to print ugly errors when AFTER_CREATE/UPDATE
event transaction semantics are violated by other parts of
the code.'

def _is_session_semantic_violated(self, context, resource, event):

    if (not context.session.is_active):
        return False
    if (not self._semantic_warned):
        stack = traceback.extract_stack()
        stack = ''.join(traceback.format_list(stack))
        LOG.warning("This    handler    is    supposed    to    handle    AFTER    events,    as    in    'AFTER    it's    committed',    not    BEFORE.    Offending    resource    event:    %(r)s,    %(e)s.    Location:\n%(l)s", {'r': resource, 'e': event, 'l': stack})
        self._semantic_warned = True
    return True
