{{{
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.
* status: new => closed
* resolution: => worksforme
Comment:
Thanks for this ticket, however it works for me. Can you provide a sample
project that reproduces the issue? Can you reproduce it on Django 4.2?
--
Ticket URL: <https://code.djangoproject.com/ticket/34495#comment:1>