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

Queryset filter doesn't evaluate translated field on ParentalManyToManyField #569

Open
urlsangel opened this issue Sep 9, 2020 · 3 comments

Comments

@urlsangel
Copy link

urlsangel commented Sep 9, 2020

I'm using Wagtail with django-modeltranslation, and ManyToManyField to form taxonomy relationships between pages and snppets with translated title and slug fields.

According to the docs, filtering on querysets should use the translated version of the field that I'm filtering on - in this case the slug field: https://django-modeltranslation.readthedocs.io/en/latest/usage.html#multilingual-manager

The SQL output below from django-debug-toolbar shows that a filter performed while the current language is set to French, the slug field is not looked up as slug_fr as expected, and the query fails to return pages related to this term.

Expected:
taxonomies_resourcetype"."slug_fr" IN ('articles-de-recherche'))

Actual query (see below for full query):
taxonomies_resourcetype"."slug" IN ('articles-de-recherche'))


SELECT ••• FROM "resources_resourcepage" INNER JOIN "wagtailtrans_translatablepage" ON ("resources_resourcepage"."translatablepage_ptr_id" = "wagtailtrans_translatablepage"."translatable_page_ptr_id") INNER JOIN "wagtailcore_page" ON ("wagtailtrans_translatablepage"."translatable_page_ptr_id" = "wagtailcore_page"."id") INNER JOIN "resources_resourcepage_resource_type" ON ("resources_resourcepage"."translatablepage_ptr_id" = "resources_resourcepage_resource_type"."resourcepage_id") INNER JOIN "taxonomies_resourcetype" ON ("resources_resourcepage_resource_type"."resourcetype_id" = "taxonomies_resourcetype"."id") WHERE ("wagtailcore_page"."path"::text LIKE '0001000200020001%' AND "wagtailcore_page"."depth" >= 4 AND NOT ("resources_resourcepage"."translatablepage_ptr_id" = 9) AND "wagtailcore_page"."depth" = 5 AND "wagtailcore_page"."live" AND "taxonomies_resourcetype"."slug" IN ('articles-de-recherche')) ORDER BY "resources_resourcepage"."published_date" DESC
--

My installed versions are:

Django==3.1
django-modeltranslation==0.15.1
wagtail==2.10
@urlsangel
Copy link
Author

Updated issue title and content, as the regular Django ManyToMany field has the same issue, and the extended version wasn't required.

@last-partizan
Copy link
Collaborator

I can't offer many help here. If you want to get it working - try to figure out what is wrong with django-modeltranslation and create merge request.

@urlsangel
Copy link
Author

Hi @last-partizan

Thanks for the update, will do :-)

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