#34889: Broken fallback for prefetchers that only implement 
get_prefetch_queryset
-------------------------------------+-------------------------------------
               Reporter:  Matt       |          Owner:  nobody
  Westcott                           |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  5.0
  layer (models, ORM)                |
               Severity:  Release    |       Keywords:
  blocker                            |
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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:

 
https://github.com/django/django/blob/4e790271e3e65c9ad037b347a34fa95e11982228/django/db/models/query.py#L2535-L2562

 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

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34889>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018afbd0c168-f24cf03a-f618-4f36-9e4b-c8ccce0a6bc5-000000%40eu-central-1.amazonses.com.

Reply via email to