#35996: Missing chunk_size throws exception when serializing many-to-many Model
field
-------------------------------------+-------------------------------------
Reporter: Erica Pisani | Owner: Erica
| Pisani
Type: Bug | Status: new
Component: Core | Version: 5.0
(Serialization) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Erica Pisani):
* needs_tests: 1 => 0
* resolution: needsinfo =>
* status: closed => new
Old description:
> Related issue: https://code.djangoproject.com/ticket/35238
>
> I'm currently upgrading a project from v4.x to v5.0.1 and, when
> attempting to save a model with a prefetched many-to-many field, the
> "ValueError: chunk_size must be provided when using QuerySet.iterator()
> after prefetch_related()" exception is thrown within the core Django
> [https://github.com/django/django/blob/9c436a09b3a641874881706495ae07293aa97c2f/django/core/serializers/python.py#L86
> serializer]:
>
> Here's the trace within my project that leads to the exception:
> {{{
> File ".../site-packages/django/db/models/base.py", line 822, in save
> self.save_base(
> File ".../site-packages/django/db/models/base.py", line 924, in
> save_base
> post_save.send(
> File ".../site-packages/django/dispatch/dispatcher.py", line 189, in
> send
> response = receiver(signal=self, sender=sender, **named)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> # The revisions files below are referring to the django-reversion library
>
> File ".../site-packages/reversion/revisions.py", line 340, in
> _post_save_receiver
> add_to_revision(instance, model_db=using)
> File ".../site-packages/reversion/revisions.py", line 209, in
> add_to_revision
> _add_to_revision(obj, db, model_db, True)
> File ".../site-packages/reversion/revisions.py", line 184, in
> _add_to_revision
> serialized_data=serializers.serialize(
> ^^^^^^^^^^^^^^^^^^^^^^
>
> File ".../site-packages/django/core/serializers/__init__.py", line 134,
> in serialize
> s.serialize(queryset, **options)
> File ".../site-packages/django/core/serializers/base.py", line 143, in
> serialize
> self.handle_m2m_field(obj, field)
> File ".../site-packages/django/core/serializers/python.py", line 91, in
> handle_m2m_field
> queryset_iterator(obj, field),
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File ".../site-packages/django/core/serializers/python.py", line 86, in
> queryset_iterator
> .iterator()
> ^^^^^^^^^^
> File ".../site-packages/django/db/models/query.py", line 532, in
> iterator
> raise ValueError(
> ValueError: chunk_size must be provided when using QuerySet.iterator()
> after prefetch_related().
> }}}
>
> I confirmed that applying the same fix as the issue linked above
> addresses the issue.
>
> **Proposed solution:**
> I'm happy to put up a pull request with the patch, and can emulate what
> the issue linked above did which is conditionally supply a `chunk_size`
> similar to the solution implemented in the issue linked above'
New description:
Related issue: https://code.djangoproject.com/ticket/35238
I'm currently upgrading a project from v4.x to v5.0.1 and, when attempting
to save a model with a prefetched many-to-many field, the "ValueError:
chunk_size must be provided when using QuerySet.iterator() after
prefetch_related()" exception is thrown within the core Django
[https://github.com/django/django/blob/9c436a09b3a641874881706495ae07293aa97c2f/django/core/serializers/python.py#L86
serializer]:
Here's the trace within my project that leads to the exception:
{{{
File ".../site-packages/django/db/models/base.py", line 822, in save
self.save_base(
File ".../site-packages/django/db/models/base.py", line 924, in
save_base
post_save.send(
File ".../site-packages/django/dispatch/dispatcher.py", line 189, in
send
response = receiver(signal=self, sender=sender, **named)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# The revisions files below are referring to the django-reversion library
File ".../site-packages/reversion/revisions.py", line 340, in
_post_save_receiver
add_to_revision(instance, model_db=using)
File ".../site-packages/reversion/revisions.py", line 209, in
add_to_revision
_add_to_revision(obj, db, model_db, True)
File ".../site-packages/reversion/revisions.py", line 184, in
_add_to_revision
serialized_data=serializers.serialize(
^^^^^^^^^^^^^^^^^^^^^^
File ".../site-packages/django/core/serializers/__init__.py", line 134, in
serialize
s.serialize(queryset, **options)
File ".../site-packages/django/core/serializers/base.py", line 143, in
serialize
self.handle_m2m_field(obj, field)
File ".../site-packages/django/core/serializers/python.py", line 91, in
handle_m2m_field
queryset_iterator(obj, field),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../site-packages/django/core/serializers/python.py", line 86, in
queryset_iterator
.iterator()
^^^^^^^^^^
File ".../site-packages/django/db/models/query.py", line 532, in
iterator
raise ValueError(
ValueError: chunk_size must be provided when using QuerySet.iterator()
after prefetch_related().
}}}
I confirmed that applying the same fix as the issue linked above addresses
the issue.
**Proposed solution:**
I've put up a pull request with the patch which mirrors what was done in
the linked issue above (conditionally adding a `chunk_size` to the
`.iterator` call).
--
--
Ticket URL: <https://code.djangoproject.com/ticket/35996#comment:8>
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/01070193b75cce87-b5de0028-4b1a-41bd-bef6-5c06a25f1bbe-000000%40eu-central-1.amazonses.com.