Warning:
Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.
| File session.close.patch,
2.4 KB
(added by paj, 4 years ago) |
|
|
-
|
|
|
|
| | 1 | |
| 1 | 2 | """Provides convenient access to an SQLObject or SQLAlchemy |
| 2 | 3 | managed database.""" |
| 3 | 4 | |
| … |
… |
|
| 403 | 404 | req.sa_transaction = make_sa_transaction(session) |
| 404 | 405 | |
| 405 | 406 | try: |
| 406 | | retval = func(*args, **kw) |
| | 407 | try: |
| | 408 | retval = func(*args, **kw) |
| 407 | 409 | |
| 408 | | except (cherrypy.HTTPRedirect, cherrypy.InternalRedirect): |
| 409 | | log.debug('this is only a redirect') |
| 410 | | # If a redirect happens; commit and proceed with redirect |
| | 410 | except (cherrypy.HTTPRedirect, cherrypy.InternalRedirect): |
| | 411 | log.debug('this is only a redirect') |
| | 412 | # If a redirect happens; commit and proceed with redirect |
| | 413 | if sa_tr_active(req.sa_transaction): |
| | 414 | req.sa_transaction.commit() |
| | 415 | raise |
| | 416 | |
| | 417 | except: |
| | 418 | log.debug('this is an exception, ROLLBACK now!') |
| | 419 | # If any other exception happens; rollback and re-raise error |
| | 420 | if sa_tr_active(req.sa_transaction): |
| | 421 | req.sa_transaction.rollback() |
| | 422 | raise |
| | 423 | |
| | 424 | # If the call was successful; commit and proceed |
| 411 | 425 | if sa_tr_active(req.sa_transaction): |
| | 426 | log.debug('The transaction was successful, COMMIT now!') |
| 412 | 427 | req.sa_transaction.commit() |
| 413 | | raise |
| | 428 | finally: |
| | 429 | # With SA 0.4, always close the session |
| | 430 | if not hasattr(session, 'context'): |
| | 431 | session.close() |
| 414 | 432 | |
| 415 | | except: |
| 416 | | log.debug('this is an exception, ROLLBACK now!') |
| 417 | | # If any other exception happens; rollback and re-raise error |
| 418 | | if sa_tr_active(req.sa_transaction): |
| 419 | | req.sa_transaction.rollback() |
| 420 | | raise |
| 421 | | |
| 422 | | # If the call was successful; commit and proceed |
| 423 | | if sa_tr_active(req.sa_transaction): |
| 424 | | log.debug('The transaction was successful, COMMIT now!') |
| 425 | | req.sa_transaction.commit() |
| 426 | | |
| 427 | 433 | return retval |
| 428 | 434 | |
| 429 | 435 | # include "args" to avoid call being pre-cached |
| … |
… |
|
| 441 | 447 | # SA 0.3 |
| 442 | 448 | return tr.session.transaction |
| 443 | 449 | else: |
| 444 | | # SA 0.4 (effectively always active - commit or rollback don't fail) |
| | 450 | # SA 0.4 can be treated as always active; if no transaction |
| | 451 | # is active, commit and rollback quietly do nothing |
| 445 | 452 | return True |
| 446 | 453 | |
| 447 | 454 | def make_sa_transaction(session): |
Download in other formats: