Hi Matt,

I think it would be preferable to use atomic() here.

>From reading the documentation 
<https://docs.djangoproject.com/en/1.8/topics/db/transactions/> it looks 
like you might already be in a transaction when calling `set_autocommit` 
but it's hard to tell without the full traceback.

What kind of errors do you get from:

def foo(request):
    with transaction.atomic():
        # ... do stuff involving multiple database actions ...

Note that you should never catch `DatabaseError` within an `atomic()` 
context. You should wrap the context managed block with a try/except 
instead:

*Wrong*
with transaction.atomic():
    try:
        # Do database stuff possibly raising database errors
    except DatabaseError:
        pass


*Right*
try:
    with transaction.atomic():
        # Do database stuff possibly raising database errors
except DatabaseError:
    pass

Simon

Le jeudi 2 avril 2015 14:42:26 UTC-4, Matt Woodward a écrit :
>
> Hi all -- I just upgraded one of my projects to Django 1.8 from 1.7.7 and 
> in a view function where we're doing manual transaction management 
> (Postgres) I'm now getting the error in the subject line.
>
> Basic gist of the code involved:
>
> def foo(request):
>   try:
>     transaction.set_autocommit(False)
>
>     ... do stuff involving multiple database actions ...
>   except (DatabaseError, Exception) as e:
>     transaction.rollback()
>
> This worked fine in 1.7.7 so I'm not sure what I need to change to get it 
> working with 1.8.
>
> I did read the docs on the atomic() functionality and took a few runs at 
> that but just wound up with different errors, so I thought I'd start with 
> what I originally had and see what I need to change to make Django 1.8 
> happy. But if using the atomic() stuff is preferable any tips around that 
> would also be appreciated; I can post the errors I'm getting when trying 
> things that way as needed.
>
> Appreciate any ideas anyone has. Thanks.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/bc17b239-b42c-4c08-80be-8e5309b10eda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to