Changeset 3433
- Timestamp:
- 08/31/07 15:23:04 (1 year ago)
- Files:
-
- branches/1.1/turbogears/errorhandling.py (modified) (4 diffs)
- branches/1.1/turbogears/tests/test_sqlalchemy.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/turbogears/errorhandling.py
r3320 r3433 1 import sys1 import sys 2 2 from itertools import izip, islice 3 3 from inspect import getargspec … … 68 68 """Call function, catch and dispatch any resulting exception.""" 69 69 # turbogears.database import here to avoid circular imports 70 from turbogears.database import _use_sa 70 from turbogears.database import _use_sa, session 71 71 try: 72 72 return func(self, *args, **kw) … … 80 80 exc_type, exc_value, exc_trace = sys.exc_info() 81 81 remove_keys(kw, ("tg_source", "tg_errors", "tg_exceptions")) 82 if _use_sa() and getattr(cherrypy.request, "in_transaction", None): 83 # using SA ? 84 # Caught pants down in the middle of a transaction :) ? 85 # rollback the transaction for this whole request 86 session.clear() 87 cherrypy.request.sa_transaction.rollback() 82 88 try: 83 89 output = dispatch_error(self, func, None, e, *args, **kw) … … 86 92 else: 87 93 del exc_trace 88 89 if _use_sa() and getattr(cherrypy.request, "in_transaction", None):90 # using SA ?91 # Caught pants down in the middle of a transaction :) ?92 # rollback the transaction for this whole request93 cherrypy.request.sa_transaction.rollback()94 95 94 return output 96 95 branches/1.1/turbogears/tests/test_sqlalchemy.py
r3431 r3433 146 146 assert 'InvalidRequestError: This transaction is inactive' not in cherrypy.response.body[0] 147 147 148 # Check an exception within a tg.exception_handler causes a rollback 149 class RbRoot(RootController): 150 def handerr(self, id): 151 Person(id=int(id)+1) 152 session.flush() 153 return dict() 154 @expose() 155 @errorhandling.exception_handler(handerr) 156 def doerr(self, id): 157 Person(id=id) 158 raise Exception('test') 159 160 def test_exc_rollback(): 161 cherrypy.root = RbRoot() 162 create_request('/doerr?id=24') 163 print cherrypy.response.body[0] 164 assert Person.get(24) is None 165 assert Person.get(25) is not None 148 166 149 167 #--