#34889 closed Bug (fixed)
Broken fallback for prefetchers that only implement get_prefetch_queryset
Reported by: | Matt Westcott | Owned by: | Mariusz Felisiak |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 5.0 |
Severity: | Release blocker | Keywords: | |
Cc: | Clément Escolano | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In #33651, the get_prefetch_queryset()
method of related managers and descriptors is deprecated in favour of get_prefetch_querysets()
. Based on the deprecation warnings, it's clear that subclasses implementing only get_prefetch_queryset()
are intended to continue working until this is removed outright in 6.0. However, the fallback code in prefetch_one_level
calls it with an invalid signature:
Here the get_prefetch_queryset
method is passed lookup.get_current_querysets(level)
- which returns a list of querysets - as the queryset
argument, which expects a single queryset. Changing this to lookup.get_current_queryset(level)
fixes the problem (although it also doubles up the deprecation warnings, which may not be ideal).
Unfortunately I'm slightly stumped over how I might create a regression test for this - presumably this would involve writing a minimal related manager class that implements get_current_queryset
but not get_current_querysets
, but since this is an internal API it's hard to know what's considered minimal while still being a legal implementation. If it's any help, I encountered this as a regression to the django-modelcluster
package: https://github.com/wagtail/django-modelcluster/actions/runs/6407673311/job/17394971115
Change History (5)
comment:1 by , 13 months ago
Cc: | added |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 13 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Great catch! I think we should still call
get_current_querysets()
, but pass only the first one when a return value is notNone
.Regression in cac94dd8aa2fb49cd2e06b5b37cf039257284bb0.