#31573: QuerySet.update().order_by() not working as expected on MySQL
-------------------------------------+-------------------------------------
               Reporter:  Gerben     |          Owner:  nobody
  Morsink                            |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  2.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:  queryset update
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 When a UniqueConstraint is used on an IntegerField and we want to update
 multiple rows of that field at once, we need to make sure we select the
 right order before the update, since MySQL does not support a deferred
 update (see: https://dev.mysql.com/doc/refman/5.7/en/update.html).

 I expected simply doing:

 qs.order_by('-integerfield').update(integerfield=F('integerfield')+1)
 would work, but it seems the Django ORM strips the order_by from the query
 before execution, it gives a django.db.utils.IntegrityError: (1062,
 "Duplicate entry '' for key 'integerfield'").

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31573>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.b05b8553486270e2bce96a4c2421ea08%40djangoproject.com.

Reply via email to