#27744: Complex prefetch_related broken (from 1.9 to 1.10) -------------------------------------+------------------------------------- Reporter: Pascal | Owner: nobody Briet | Type: Bug | Status: new Component: Database | Version: 1.10 layer (models, ORM) | Severity: Normal | Keywords: prefetch Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -------------------------------------+------------------------------------- Was working on : 1.9.10 Is not working on : 1.10.5
{{{ #!div style="font-size: 80%" {{{#!python from offer.models import Price, PriceGrid from django.db.models import Prefetch price_queryset = Price.objects.prefetch_related('calculation_rules__rule') pricegrids = PriceGrid.objects.all() pricegrids = pricegrids.prefetch_related(Prefetch('prices', queryset=price_queryset)) for pg in pricegrids: print(pg.pk) }}} }}} `AttributeError: Cannot find 'rule' on RelatedManager object, 'prices__calculation_rules__rule' is an invalid parameter to prefetch_related()` But this still works : {{{ #!div style="font-size: 80%" {{{#!python pgs = PriceGrid.objects.prefetch_related('prices__calculation_rules__rule').all() for pg in pgs: for price in pg.prices.all(): for dr in price.calculation_rules.all(): print(dr.rule.pk) }}} }}} Models (extracts) : {{{ #!div style="font-size: 80%" {{{#!python class Price(models.Model): grid = models.ForeignKey(PriceGrid, related_name="prices") class PriceCalculationRule(models.Model): price = models.ForeignKey(Price, on_delete=models.CASCADE, related_name="calculation_rules") rule = models.ForeignKey(Rule, on_delete=models.PROTECT, verbose_name="Condition") }}} }}} -- Ticket URL: <https://code.djangoproject.com/ticket/27744> 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 post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/049.7dcea7ff47a313cbea3d97f8c9a1fa0c%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.