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 and other expressions in annotate() #728

Open
celyes opened this issue Apr 19, 2024 · 5 comments
Open

Support for Subquery and other expressions in annotate() #728

celyes opened this issue Apr 19, 2024 · 5 comments

Comments

@celyes
Copy link

celyes commented Apr 19, 2024

Thank you for this awesome package.

The plugin works perfectly for our needs except, however, when used with the annotate() where the annotate contains a Subquery expression or an F expression, it doesn't use the current language. For example, if the Subquery asks for a field called 'title', it's supposed to query title_en or title_fr or whatever is the current language but instead, it raises this exception:

FieldError: Cannot resolve expression type, unknown output_field.

Once specifying the output_field, we get this exception:

 # FieldType is the type of the field specified. e.g: CharField
QuerySet.annotate() received non-expression(s): <django.db.models.fields.FieldType>

Any idea how to work around this issue?

@celyes celyes changed the title Support for Subquery and F expressions in annotate() Support for Subquery and other expressions in annotate() Apr 19, 2024
@last-partizan
Copy link
Collaborator

Hi, the only workaround is to use translated field name instead of generic name.

But, you can look at the source code and try to add this feature. I'll gladly review and merge it.

@celyes
Copy link
Author

celyes commented Apr 24, 2024

Sure I'll add it @last-partizan. can you just direct me to where i should focus on so I can add it? thank you.

@last-partizan
Copy link
Collaborator

@celyes start by adding a test-case, and then - look at the MultilingualQuerySet source code, probably you need to override annotate method, or maybe some other places there.

@celyes
Copy link
Author

celyes commented Apr 25, 2024

Thank you

@wookkl
Copy link
Contributor

wookkl commented May 20, 2024

Could you please share the test code that is causing the error? I would like to help resolve this issue as well.

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

3 participants