#27403: Document that prefetch_related doesn't guarantee transactional
consistency
--------------------------------------+------------------------------------
Reporter: Aymeric Augustin | Owner: Tim Bell
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Bell):
* owner: nobody => Tim Bell
* status: new => assigned
Comment:
I'm looking at this ticket during the DjangoCon sprints.
I've reproduced a version of this race condition using the models defined
in the `prefetch_related()` docs
(https://docs.djangoproject.com/en/4.2/ref/models/querysets/#prefetch-
related). By adding a `sleep()` at the start of
`prefetch_related_objects()`, I was able to run another database query in
between the two queries required to evaluate
`Pizza.objects.prefetch_related('toppings')`.
When deleting `Pizza.objects.get(name="Hawaiian")` during the sleep, we
get this:
{{{
>>> Pizza.objects.prefetch_related('toppings')
Sleeping...
<QuerySet [<Pizza: Hawaiian ()>, <Pizza: Seafood (prawns, smoked
salmon)>]>
}}}
Just like in the example from this ticket's description, at no point in
the history did the database look like this.
I'll now try to write a succinct description of this issue (only one or
two sentences) to add to the docs.
--
Ticket URL: <https://code.djangoproject.com/ticket/27403#comment:5>
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 on the web visit
https://groups.google.com/d/msgid/django-updates/0107018b4d8d83cf-11100ac6-34d9-4673-94e2-329ade5caa49-000000%40eu-central-1.amazonses.com.