Django Gets Transactions

Jacob Kaplan-Moss added transaction support to the magic-removal branch of Django just a few minutes ago. It’s one of the many changes to come out of the sprint. Usage will look something like this (based on Jacob’s docs and chatting with him in #django-sprint):

from django.db import transaction

@transaction.commit_manually def view(request): # you make changes to your objects, calling on them as normal

# when you commit, all changes to all objects will be commited to your database transaction.commit()

# an excellent idea would be to wrap in a try/except block try: # do your stuff except: transaction.rollback() else: transaction.commit()

I couldn’t find a good doc quick for Python decorators (that bit with the @ before the function declaration) for people who haven’t used them before, so if someone has a good one, please post it in the comments below.

Here’s a link to the full docs and for those interested in the nitty-gritty, here’s a link to the code checkin.

And before you ask, magic-removal is expected to be merged to trunk before the end of March.