Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when a model with multi-table inheritance also has default ordering #703

Open
ryselis opened this issue Sep 13, 2023 · 1 comment
Open

Comments

@ryselis
Copy link

ryselis commented Sep 13, 2023

Consider the following models:

class OrderGood(models.Model):
    pass


class SupplyOrderGoodServiceBase(models.Model):
    supplier_price = models.DecimalField(max_digits=12, decimal_places=4)
    title = models.CharField(max_length=512)

    class Meta:
        ordering = ('id',)


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

Title field must be translated, the options are configured as follows:

@register(SupplyOrderGoodServiceBase)
class SupplyOrderGoodServiceBaseTranslation(TranslationOptions):
    fields = ('title',)


@register(SupplyOrderGood)
class SupplyOrderGoodServiceBaseTranslation(TranslationOptions):
    fields = ()

However, update queries do not work due to default ordering being added to order_by. Consider this query:

SupplyOrderGood.objects.filter(order_good_id=self.order_good.pk).update(supplier_price=Decimal(6))

It generates the following query:

 ORDER BY `supply_supplyordergood`.`supplyordergoodservicebase_ptr_id` ASC

I believe this happens only on MySQL as the incompatibility comes from SQLUpdateCompiler class for MySQL. update_query and update_params are both empty, but self.query.order_by is not, which leads to this query with only the ORDER BY part.

I uploaded an example project here https://github.com/ryselis/django_34495
There is a failing test in supply/tests.py

@last-partizan
Copy link
Collaborator

Hi, thanks for the report.

If you can trace it deeper and make PR with a fix, i can merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants