#37027: refresh_from_db() with from_queryset + prefetch does not persist result
in
instance
-------------------------------------+-------------------------------------
Reporter: Hugo Maingonnat | Type: Bug
Status: new | Component: Database
| layer (models, ORM)
Version: 5.2 | Severity: Normal
Keywords: refresh_from_db, | Triage Stage:
prefetch | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
{{{
foo = Foo.objects.create(**data)
# The prefetch query is executed, but does not seem to be persisted into
the instance
prefetch = Prefetch('bar_set', queryset=Bar.objects.all())
foo.refresh_from_db(from_queryset=Foo.objects.prefetch_related(
prefetch
))
# This is empty
print('CACHE:', foo._prefetched_objects_cache)
# Lazy extra query is executed because prefetch was not persisted: this
should not happen
list(foo.bar_set.all())
}}}
This also does not work if for example `to_attr='bar_list'` is set in the
prefetch, then `foo.bar_list` is not set.
Note that using `select_related()` is working.
--
Ticket URL: <https://code.djangoproject.com/ticket/37027>
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 [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019d724c8885-928d9b1b-e15a-4ea8-90f1-09bc94cb2cee-000000%40eu-central-1.amazonses.com.