From: Elrond Date: Sat, 28 Jan 2012 12:10:01 +0000 (+0100) Subject: Cleanup Session after each request. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2bc8ff0d63188f2168553d39ebf8756ae83053e1;p=mediagoblin.git Cleanup Session after each request. It's good practice to cleanup the SQL session after each request so that the next request gets a fresh one. It's an application decision whether one wants a just-in-case ROLLBACK or COMMIT. There are two ideas behind it, really. I have decided for ROLLBACK. The idea is "if you forget to commit your changes yourself, there's something broken. Maybe you got an exception?". --- diff --git a/mediagoblin/app.py b/mediagoblin/app.py index 15327d39..0a57c091 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -184,6 +184,14 @@ class MediaGoblinApp(object): for m in self.meddleware[::-1]: m.process_response(request, response) + # Reset the sql session, so that the next request + # gets a fresh session + try: + self.db.reset_after_request() + except TypeError: + # We're still on mongo + pass + return response(environ, start_response) diff --git a/mediagoblin/db/sql/open.py b/mediagoblin/db/sql/open.py index 1bfc5538..a8677bcb 100644 --- a/mediagoblin/db/sql/open.py +++ b/mediagoblin/db/sql/open.py @@ -36,6 +36,7 @@ class DatabaseMaster(object): Session.flush() def reset_after_request(self): + Session.rollback() Session.remove()