#33841: Django shouldn't fail (bulk-)update silently when QuerySet is already
evaluated / update documentation
-------------------------------------+-------------------------------------
Reporter: SHxKM | Owner: nobody
Type: | Status: new
Uncategorized |
Component: Database | Version: 3.2
layer (models, ORM) | Keywords: update, bulk-
Severity: Normal | update, queryset
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The following code:
{{{
initial_queryset = MyObject.objects.filter(...)
filtered_queryset = initial_queryset.exclude(related_model__id__in=...)
for_loop_on_filtered = [MyOtherModel(some_id=..., other_id=...) for x in
filtered_queryset]
MyOtherModel.objects.bulk_create(for_loop_on_filtered)
filtered_queryset.update(processed=True) # silent failure to update
}}}
Fails to update all objects in `filtered_queryset`. It seems like the
reason is the list-comprehension on `filtered_queryset`.
I've been with Django for >6 years and this is by far the most surprising
behavior I've seen.
It does seem to be documented (?):
"You cannot call update() on a QuerySet that has had a slice taken or can
otherwise no longer be filtered."
But the fact is I can and did call `update()` on that QuerySet, and Django
returned 0 errors.
If that is the intended behavior, then I suggest updating the
documentation.
--
Ticket URL: <https://code.djangoproject.com/ticket/33841>
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/01070181f4769eb1-d1b3d6ad-7088-474f-819f-7f3c78416758-000000%40eu-central-1.amazonses.com.