On Thu, Aug 9, 2012 at 5:58 PM, Cal Leeming [Simplicity Media Ltd] < [email protected]> wrote:
> Sorry, please ignore that last message, I see now that you > were referring to this: > > https://docs.djangoproject.com/en/dev/ref/databases/#autocommit-mode > > So essentially, the official documentation would state that to resolve > this problem, you would use the following for your db settings: > > 'OPTIONS': { > 'autocommit': True, > } > > Is that correct? > No...that syntax is pulled out of a PostgreSQL doc note and I don't think it would work with MySQL, though I am not entirely sure of that. Also I am not sure I would recommend a global DB level setting for this -- you're dispensing with any transactions at that point, which may well be inappropriate for an app that is having trouble with get_or_create. It's very hard for Django to give explicit instructions for what is best to do "in general" since it all depends on the needs of the application with respect to transactions. I would say in general I'd recommend "read committed" isolation level vs. database-level autocommit, but the ticket noted that read committed "can break legacy apps" (why, I'm not sure, and it doesn't explain), so for the sake of completeness I mentioned that database level autocommit would also fix the race condition that exists in get_or_create. I don't believe the doc can give a blanket "do this and your code will work" statement here. It can say Django's own code in get_or_create requires either that the transaction isolation level be set to "read committed" or DB level autocommit be used. Whether that is best done for the project globally via an init_command or only for certain requests via explicit cursor commands (see http://groups.google.com/group/django-users/msg/55fa3724d2754013) depends on the project itself and what else it is doing besides calling get_or_create. Karen -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
