#2705: [patch] Add optional FOR UPDATE clause to QuerySets ---------------------------------------------------+------------------------ Reporter: Hawkeye | Owner: nobody Status: new | Milestone: Component: Database layer (models, ORM) | Version: SVN Resolution: | Keywords: Stage: Accepted | Has_patch: 1 Needs_docs: 0 | Needs_tests: 0 Needs_better_patch: 1 | ---------------------------------------------------+------------------------ Comment (by liangent):
Replying to [comment:37 anih]: > Replying to [comment:36 liangent]: > > > in that marked line, if i don't specify force_update=True, it will do an INSERT, which will cause an IntegrityError. {{{ IntegrityError: (1062, "Duplicate entry '11' for key 1") }}} > > i try to reproduce this problem but without success, could you paste model file and separate some test? > > i send patch to trunk version with transaction.commit_unless_managed() inside select_for_update() (django/db/models/query.py) > > i dont have oracle to make some tests, but im using this patch with postgresql for about 1/2 year (note: 1. 'key 1' is the primary key; 2. i'm using mysql: 5.0.67-0ubuntu6) i think it has nothing to do with the models. as i know, django try to SELECT a row when we're going to .save() to know if the row exists. however, because i used SELECT FOR UPDATE, mysql locked the row, and django cannot find it with SELECT, so django decides to INSERT. since the field 'id' in object 't' has been set and value is assigned to an existing row ('t' was got from a SELECT FOR UPDATE), an IntegrityError is raised. -- Ticket URL: <http://code.djangoproject.com/ticket/2705#comment:41> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---