From: Ant Zucaro Date: Sat, 8 Sep 2012 18:37:18 +0000 (-0400) Subject: Use a dummy session variable. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=cf4e74be3b45d840434ff70c962af1f0cfb78610;p=xonotic%2Fxonstat.git 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. --- 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