Thanks so much for the quick and thorough reply! I think I'm set now with the "Right" example below -- I was getting errors (the most cryptic of which was just "__exit__") when I was trying various incarnations of atomic but it seems to be working now using the example you provided.
The last thing I need to verify is the behavior change around assigning unsaved objects to relations since in this particular case I'm creating a new object and then saving other objects that have the first one as a FK, but that's looking good thus far in testing. Thanks again for your help -- much appreciated! Matt On Thursday, April 2, 2015 at 12:09:59 PM UTC-7, Simon Charette wrote: > > 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 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/02966744-31f5-496b-8f44-fcb551b4184c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.