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

Support for Subquery #702

Open
mick88 opened this issue Sep 12, 2023 · 5 comments
Open

Support for Subquery #702

mick88 opened this issue Sep 12, 2023 · 5 comments

Comments

@mick88
Copy link
Contributor

mick88 commented Sep 12, 2023

I have the followinmg subquery that should annotate a user with their team name:

Subquery(Team.objects.filter(users__pk=OuterRef('pk')).order_by('order').values_list('name', flat=True)[:1])

However, this code fails for non-default locale because modeltranslation replaces values_list('name', flat=True) internally with values_list('name_en', 'name_es', flat=True)

This results in the following error when trying to annotate a queryset:

django.core.exceptions.FieldError: Cannot resolve expression type, unknown output_field

Defining output_field makes the error clearer:

django.db.utils.ProgrammingError: subquery must return only one column

@last-partizan
Copy link
Collaborator

Hi, thanks for reporting.

If you can, please try to dig this issue further and make PR with a fix.

@roboxdev
Copy link

roboxdev commented Feb 6, 2024

I've faced the same issue.

@celyes
Copy link

celyes commented Apr 18, 2024

Any solutions to this problem? any workarounds? @mick88 I'm facing the same issue

@mick88
Copy link
Contributor Author

mick88 commented Apr 18, 2024

No @celyes, I don't understand the code of this library well enough to contribute. I worked around the issue by not using a Subquery for now.

@celyes
Copy link

celyes commented Apr 18, 2024

@mick88 that's a choice that I cannot make on my current project. The project I'm working on relies heavily on advanced features of the ORM so I'll either have to find a workaround or just ditch the library in favor of another one. Anyway, thanks for your reply. I appreciate 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

4 participants