Warning:
Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.
Ticket #1721: turbogears-sqlalchemy-0.4-rollback.patch
| File turbogears-sqlalchemy-0.4-rollback.patch,
1.5 KB
(added by toshio, 4 years ago) |
|
Implement exception checking and rollback in sa_rwt()
|
-
|
old
|
new
|
def sa_rwt(func, *args, **kw): |
| 405 | 405 | try: |
| 406 | 406 | retval = func(*args, **kw) |
| 407 | 407 | |
| 408 | | except (cherrypy.HTTPRedirect, cherrypy.InternalRedirect): |
| | 408 | except (cherrypy.HTTPRedirect, cherrypy.InternalRedirect), e: |
| 409 | 409 | log.debug('this is only a redirect') |
| 410 | 410 | # If a redirect happens; commit and proceed with redirect |
| 411 | 411 | if sa_tr_active(req.sa_transaction): |
| 412 | | req.sa_transaction.commit() |
| 413 | | raise |
| | 412 | try: |
| | 413 | req.sa_transaction.commit() |
| | 414 | except sqlalchemy.exceptions.InvalidRequestError: |
| | 415 | req.sa_transaction.rollback() |
| | 416 | raise e |
| 414 | 417 | |
| 415 | 418 | except: |
| 416 | 419 | log.debug('this is an exception, ROLLBACK now!') |
| … |
… |
def sa_rwt(func, *args, **kw): |
| 421 | 424 | |
| 422 | 425 | # If the call was successful; commit and proceed |
| 423 | 426 | if sa_tr_active(req.sa_transaction): |
| 424 | | log.debug('The transaction was successful, COMMIT now!') |
| 425 | | req.sa_transaction.commit() |
| | 427 | try: |
| | 428 | log.debug('Transaction successful, try commit') |
| | 429 | req.sa_transaction.commit() |
| | 430 | log.debug('Commit successful') |
| | 431 | except sqlalchemy.exceptions.InvalidRequestError: |
| | 432 | log.debug('Commit unsuccessful, ROLLBACK now!') |
| | 433 | req.sa_transaction.rollback() |
| 426 | 434 | |
| 427 | 435 | return retval |
| 428 | 436 | |
Download in other formats: