﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34495	Queryset update fails when updating parent model field with default ordering on MySQL backend	Karolis Ryselis	nobody	"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."	Bug	closed	Database layer (models, ORM)	3.2	Normal	worksforme			Unreviewed	0	0	0	0	0	0
