#34495: Queryset update fails when updating parent model field with default
ordering on MySQL backend
-------------------------------------+-------------------------------------
               Reporter:  Karolis    |          Owner:  nobody
  Ryselis                            |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  3.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 consider the following models:

 {{{
 class SupplyOrderGoodServiceBase(models.Model):
     supplier_price = models.DecimalField(max_digits=12, decimal_places=4)

     class Meta:
         ordering = ('id',)

 class SupplyOrderGood(SupplyOrderGoodServiceBase):
     order_good = models.ForeignKey(to="sales.OrderGood",
 on_delete=models.CASCADE)
 }}}

 Running the following query fails:

 {{{
 
SupplyOrderGood.objects.filter(order_good_id=order_good.pk).update(supplier_price=supplier_price)
 }}}

 This happens because the `SupplyOrderGood` instances do not have to be
 updated, the update is on `SupplyOrderGoodServiceBase`.
 `SQLUpdateCompiler` generates no SQL for `SupplyOrderGood` (`as_sql`
 returns `'', []`). However, MySQL's `SQLUpdateCompiler` finds
 `self.query.order_by` to be not empty and adds `ORDER BY` to an empty SQL
 query. Therefore, it tries to run SQL query ` ORDER BY
 `sales_supplyordergood`.`supplyordergoodservicebase_ptr_id` ASC`, which,
 of course, fails.

 This can be worked around by added an `.order_by()` to the query.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34495>
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/010701877f5a1c43-d2ed1e4c-c14a-47c9-8cbb-ddfec0caa2f4-000000%40eu-central-1.amazonses.com.

Reply via email to