« On Pause | Main | Turning off RSS1.0 »

Transactions in Django

Nice. Django gets transactions. Txn support is called in via Python decorators, so it's nice and clean on the code. Java folks used to XDoclet and attributes will appreciate the idiom:

There are 3 decorators - autocommit, commit_on_success, commit_manually. You decorate on the view code:

   from django.db.transaction import autocommit

   def doSomething(request):
       # do work

   def doSomethingElse(request):
       # do work

  def doSomethingElseAgain(request):
 	            # do work

To back out of the transaction, the view code needs to throw an exception, otherwise Django will complete. If you have view code which swallows exceptions, you might want to clean that up in preparation for this feature.

If you think you're hard enough, you can set DISABLE_TRANSACTION_MANAGEMENT=True in your settings.py file.

via Peter Harkins, who says the magic-removal branch is getting folded in in a month or so. Outstanding.

March 5, 2006 03:52 PM


Post a comment

(you may use HTML tags for style)

Remember Me?

Trackback Pings

TrackBack URL for this entry: