Browse files

Perform a session rollback in CRC if needed

At the moment, tgext.crud or sprox don't perform a rollback, but it's
needed or all session-bound objects won't be accessible in the
error_handler page.

More or less fixes #86.
  • Loading branch information...
1 parent dcff939 commit a7a2867cac8a255cbc6e804e33f922be3736b589 @moschlar committed Nov 12, 2012
Showing with 15 additions and 3 deletions.
  1. +14 −2 sauce/controllers/
  2. +1 −1 sauce/model/
@@ -7,12 +7,14 @@
@author: moschlar
+import sys
import logging
from itertools import groupby
from tg import expose, tmpl_context as c, request, flash, lurl, abort
-from tg.decorators import before_validate, cached_property, before_render, override_template
+from tg.decorators import before_validate, before_call, before_render,\
+ cached_property, override_template
from tgext.crud import CrudRestController, EasyCrudRestController
#from tw2.forms import TextField, SingleSelectField, Label, TextArea, CheckBox
@@ -33,7 +35,9 @@
Assignment, Test, NewsItem)
from sauce.widgets.datagrid import JSSortableDataGrid
from webhelpers.html.builder import literal
-from import RelationshipProperty
+from sqlalchemy.exc import IntegrityError, DatabaseError, ProgrammingError
+errors = (IntegrityError, DatabaseError, ProgrammingError)
__all__ = ['TeamsCrudController', 'StudentsCrudController', 'TutorsCrudController',
'TeachersCrudController', 'EventsCrudController', 'LessonsCrudController',
@@ -335,15 +339,23 @@ def injector(cls, remainder, params):
for i in s.inject:
params[i] = s.inject[i]
+ @staticmethod
+ def rollback(remainder, params):
+ '''Perform a session rollback when tgext.crud and/or sprox don't do'''
+ if sys.exc_info()[0] in errors:
+ DBSession.rollback()
# Register injection hook for POST requests
# Register hook for get_all
# Register hook for new
# Register hook for edit
@@ -13,7 +13,7 @@
# Global session manager: DBSession() returns the Thread-local
# session object appropriate for the current web request.
-maker = sessionmaker(autoflush=True, autocommit=False, expire_on_commit=False,
+maker = sessionmaker(autoflush=True, autocommit=False, expire_on_commit=False,
DBSession = scoped_session(maker)

0 comments on commit a7a2867

Please sign in to comment.