A little while ago I moved down the creation of the actual
DBSession() below the precondition checks to avoid unnecessary
rollback transactions. What I didn't do was check if the session
existed before using it, so when precondition checks failed I was
calling a variable that wasn't defined yet (another exception).
This adds a dummy session variable that I can check before rolling
back, avoiding more exceptions.
Entry handler for POST stats submissions.
"""
try:
+ # placeholder for the actual session
+ session = None
+
log.debug("\n----- BEGIN REQUEST BODY -----\n" + request.body +
"----- END REQUEST BODY -----\n\n")
log.debug('Success! Stats recorded.')
return Response('200 OK')
except Exception as e:
- session.rollback()
+ if session:
+ session.rollback()
return e