From cf4e74be3b45d840434ff70c962af1f0cfb78610 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Sat, 8 Sep 2012 14:37:18 -0400 Subject: [PATCH] Use a dummy session variable. 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. --- xonstat/views/submission.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xonstat/views/submission.py b/xonstat/views/submission.py index d17292d..c248f42 100644 --- a/xonstat/views/submission.py +++ b/xonstat/views/submission.py @@ -562,6 +562,9 @@ def stats_submit(request): 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") @@ -648,5 +651,6 @@ def stats_submit(request): log.debug('Success! Stats recorded.') return Response('200 OK') except Exception as e: - session.rollback() + if session: + session.rollback() return e -- 2.39.2