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 #1377 (closed defect: fixed)

Opened 12 years ago

Last modified 12 years ago

[PATCH] prevent un-completed transactions when using SQLAlchemy

Reported by: corvus Owned by: anonymous
Priority: normal Milestone: 1.0.4
Component: SQLAlchemy Version: 1.0.1
Severity: major Keywords:
Cc:

Description (last modified by Chris Arndt) (diff)

The "run with transaction" function for SQLAlchemy (sa_rwt) catches exceptions and issues a rollback before propagating the error. But it does not catch objects that are not derived from the Exception class. Any object is a legitimate exception in python, and any exception should trigger a rollback; otherwise the transaction may stay open forever and starve other processes of database resources.

In particular, some Python exceptions (such as strings) are not derived from Exception.

This patch adds a catch-all exception handler that issues a rollback and then re-raises the exception. This is the behavior found in so_rwt (the "run with transaction" function for SQLObject).

See also #1454

Attachments

tgdb.patch Download (376 bytes) - added by corvus 12 years ago.
patch to database.py

Change History

Changed 12 years ago by corvus

patch to database.py

comment:1 Changed 12 years ago by paj

  • Component changed from TurboGears to SQLAlchemy

comment:2 Changed 12 years ago by faide

Do you have a use case where non-base-Exception exceptions are raised ?

  • Since python 2.2 string exceptions are intended to be deprecated.
  • Since 2.5 I think you even get a warning message when raising such things.
  • Python 3 will completely deprecate and remove string exceptions and force all to derive from Exception.

I am not against this patch but would like to make sure we really need it.

comment:3 Changed 12 years ago by Chris Arndt

  • Milestone changed from 1.0.3 to 1.0.4

Batch promoting 1.0.3 tickets to Milestone 1.0.4

comment:4 Changed 12 years ago by Chris Arndt

  • Description modified (diff)

comment:5 Changed 12 years ago by chrisz

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in r3380.

Note: See TracTickets for help on using tickets.