Guys,

Looking for a little bit of help here understanding ATOMIC_REQUEST in 
Django 1.6

I've posted the question on Stack Overflow

http://stackoverflow.com/questions/20682954/atomic-request-and-transactions-in-django-1-6

But I thought I would try here as well.  I'll copy the question below 
(would appreciate any advice):  

given the following code:

from django.db import transaction
@transaction.atomicdef viewfunc(request):
    # This code executes inside a transaction.
    do_stuff()

>From my understanding of transactions in Django 1.6 if do_stuff throws an 
exception, say an IntegrityError, then the transaction will be rolled back 
right. But since Django itself is calling the view nothing will stop the 
IntegrityError from rising up the call stack and causing an HTTP 500 error 
yes? Let's assume that's not what we want, as we want to gracefully handle 
the error, but still get the rollback functionality.

So I guess the obvious thought is well, don't do that, use 
transaction.atomic as a context manager that is wrapped in a try except 
block like the example here:

try:
    with transaction.atomic():
        generate_relationships()except IntegrityError:
    handle_exception()

Fine. But then if you want to use the Transaction per HTTP Request 
functionality by setting ATOMIC_REQUEST = True in your db config, which 
means django will in effect just add thetransaction.atomic decorate to your 
view, which won't catch any exceptions. How is ATOMIC_REQUEST even useful? 
Why would you ever want to let your Database errors propagate all the way 
up to the user?

So my question is.

   1. What am I missing here or is my understanding correct?
   2. If I'm correct what is a use case for using ATOMIC_REQUEST? Am I 
   expected to write aurls.hadler500 or should I implement some middle wear 
   to catch the errors?

Someone please shed some light on this for me.

Thanks in advance.

j1z0

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d005617e-0dbc-4ca6-8ce6-d16bf7f7fde3%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to