Skip to content
New issue

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

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

Already on GitHub? # to your account

Broken usage of values_list together with annotate #635

Closed
rastytheamateur opened this issue May 2, 2022 · 3 comments
Closed

Broken usage of values_list together with annotate #635

rastytheamateur opened this issue May 2, 2022 · 3 comments

Comments

@rastytheamateur
Copy link

As I have mentioned in the PR, the release 0.17.6 has broken the usage of .annotate(*).values_list(*).

In previous version 0.17.5, it was working well:

MyModel.objects.filter(relatedmodel__isnull=False).annotate(Count('id')).values_list(
    'id', 'name').order_by('name').query
>>> SELECT "app_mymodel"."name_en", "app_mymodel"."id" FROM "app_mymodel"
    INNER JOIN "app_relatedmodel" ON ("app_mymodel"."id" = "app_relatedmodel"."mymodel_id")
    WHERE "app_relatedmodel"."id" IS NOT NULL
    GROUP BY "app_mymodel"."id"
    ORDER BY "app_mymodel"."name_en" ASC

while in the newest version 0.17.6 you receive by the very same query a different SQL and results as well:

MyModel.objects.filter(relatedmodel__isnull=False).annotate(Count('id')).values_list(
    'id', 'name').order_by('name').query
>>> SELECT "app_mymodel"."id", "app_mymodel"."name_en", COUNT("app_mymodel"."id") AS "id__count" FROM "app_mymodel"
    INNER JOIN "app_relatedmodel" ON ("app_mymodel"."id" = "app_relatedmodel"."mymodel_id")
    WHERE "app_relatedmodel"."id" IS NOT NULL
    GROUP BY "app_mymodel"."id"
    ORDER BY "app_mymodel"."name_en" ASC

Note the difference in the SELECT clause. Incorrect order, incorrect number of fields and one incorrect field at all.

@last-partizan
Copy link
Collaborator

@rastytheamateur does this #634 PR resolves issue?

@rastytheamateur
Copy link
Author

@last-partizan Yes, sir, it does! :-) Looking forward to the next release :-)

@last-partizan
Copy link
Collaborator

Released!

Please consider any way to help Ukraine defeat Russia. I'm safe becouse Ukrainian Army is protecting me, but we need support: https://supportukrainenow.org/

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

No branches or pull requests

2 participants