I have a pretty standard setup of Pyramid and SQLAlchemy, based
off
http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/database/sqlalchemy.html
However, this has a problem: The `cleanup` callback executes *after* the
tween has returned. I use tweens for both error logging (Rollbar) and
request logging (output via python-fluent-loggerd). This means that if the
commit and associated flush fail, neither my request logger nor error
logging catch it.
For example, if my tween looked like this:
class Tween:
def __init__(self, handler, register):
self.handler = handler
def __call__(self, request):
start = time()
response = self.handler(request)
duration = time() - start
log(duration, response.status_code) # This shows a success
return response # session.commit() fails sometime after this
The log call would report an HTTP 200, even the end result may be a HTTP
500 due to a failure in session.commt()
The obvious solution is to move logging to the WSGI middleware layer, but
then I lose all the Pyramid-specific details, which I am loath to do. I
could also manually add a try/except to handle errors in the cleanup and
report to Rollbar, but that still means my request logs show a success.
Is there a way I can force SQLAlchemy to commit/rollback (or at least
flush) before the passing the baton back to the tweens?
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pylons-discuss/a98bf35f-d120-40b4-8168-fe4fc2f09f84%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.