Wagtail: Why does ParentalManyToManyField not support prefetch_related()? Can that be fixed?

Created on 20 Sep 2018  路  3Comments  路  Source: wagtail/wagtail

I just ran into this exception when trying to use prefetch_related() on a ParentalManyToManyField called sponsors on my EventPage page model:

'sponsors' does not resolve to an item that supports prefetching - this is an invalid parameter to prefetch_related().

Why does this happen? It's going to be pretty important for performance on my site to be able to prefetch all the many-to-many relationships on EventPages, since they need to be rendered and filtered on for various displays in the Calendar.

Is there an alternative that I could use, somehow, to retain prefetch_related() functionality? Or maybe a different way of doing the same thing as prefetch_related()?

Most helpful comment

I've opened a PR at https://github.com/wagtail/django-modelcluster/pull/122 to try to address this -- posting here since most Wagtail users might not be tracking that repository. Any and all testing of that proposal would be appreciated, as it'd be great to have prefetch support for ParentalManyToManyFields.

All 3 comments

FWIW, a similar issue/question raised at https://github.com/wagtail/django-modelcluster/issues/101

Thank you for the report @coredumperror and the link to modelcluster repo @zerolab. Since it's indeed an issue related to modelcluster itself, I encourage you to continue the discussion there.

I've opened a PR at https://github.com/wagtail/django-modelcluster/pull/122 to try to address this -- posting here since most Wagtail users might not be tracking that repository. Any and all testing of that proposal would be appreciated, as it'd be great to have prefetch support for ParentalManyToManyFields.

Was this page helpful?
0 / 5 - 0 ratings