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

MultilingualQueryset breaks grouping with limit #559

Open
ryselis opened this issue Jun 11, 2020 · 0 comments
Open

MultilingualQueryset breaks grouping with limit #559

ryselis opened this issue Jun 11, 2020 · 0 comments

Comments

@ryselis
Copy link

ryselis commented Jun 11, 2020

Consider the following model:

class AdvanceBill(models.Model):
    date = models.DateField()
    total = models.DecimalField(max_digits=12, decimal_places=2)
    number = models.CharField(max_length=10)
    # other fields

    class Meta:
        ordering = ("-date", "-number")

If I try running the following statement:

AdvanceBill.objects.all().values("date").annotate(x_total_sum=Sum(F("total"))).order_by()[:10]

the result is not grouped by values (the same dates have multiple occurences in the result) as the query looks like this (note that values only accept "date" and we have date and number in GROUP BY clause and ORDER BY is applied anyway):

SELECT `accounting_advancebill`.`date`, SUM(`accounting_advancebill`.`total`) AS `x_total_sum` FROM `accounting_advancebill` GROUP BY `accounting_advancebill`.`date`, `accounting_advancebill`.`number` ORDER BY `accounting_advancebill`.`date` DESC, `accounting_advancebill`.`number` DESC LIMIT 10

This happens when the model uses MultilingualQuerySet, (MultilingualManager) if standard QuerySet is used, order_by() removes ordering as expected:

SELECT `accounting_advancebill`.`date`, SUM(`accounting_advancebill`.`total`) AS `x_total_sum` FROM `accounting_advancebill` GROUP BY `accounting_advancebill`.`date` ORDER BY NULL LIMIT 10

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

1 participant