#35996: Missing chunk_size throws exception when serializing many-to-many Model
field
-------------------------------------+-------------------------------------
Reporter: Erica Pisani | Owner: Erica
| Pisani
Type: Bug | Status: closed
Component: Core | Version: 5.0
(Serialization) |
Severity: Release blocker | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Erica Pisani):
Hi Sarah,
I've tried upgrading to Django 5.1.4 and the issue still exists (and it
still does on the main branch of the Django repository as well).
For steps to reproduce:
We can use these models within the Django test suite in
`tests/serializers/models/base.py`:
{{{
class CategoryMetaData(models.Model):
kind = models.CharField(max_length=10)
name = models.CharField(max_length=10)
value = models.CharField(max_length=10)
objects = CategoryMetaDataManager()
class Category(models.Model):
name = models.CharField(max_length=20)
meta_data = models.ForeignKey(
CategoryMetaData, models.SET_NULL, null=True, default=None
)
class Article(models.Model):
author = models.ForeignKey(Author, models.CASCADE)
headline = models.CharField(max_length=50)
pub_date = models.DateTimeField()
categories = models.ManyToManyField(Category)
meta_data = models.ManyToManyField(CategoryMetaData)
topics = models.ManyToManyField(Topic)
}}}
if `test_serialize_prefetch_related_m2m` in `tests/serializers/tests.py`
were updated from:
{{{
with self.assertNumQueries(4):
serializers.serialize(
self.serializer_name,
Article.objects.prefetch_related("categories",
"meta_data", "topics"),
)
with self.assertNumQueries(7):
serializers.serialize(self.serializer_name,
Article.objects.all())
}}}
to the following:
{{{
with self.assertNumQueries(4):
serializers.serialize(
self.serializer_name,
Article.objects.prefetch_related(
"meta_data",
"topics",
Prefetch(
"categories",
queryset=Category.objects.prefetch_related("meta_data"),
)
with self.assertNumQueries(7):
serializers.serialize(self.serializer_name,
Article.objects.all())
}}}
the ValueError related to missing chunk_size will be raised in the JSON,
YAML, and XML serializers.
--
Ticket URL: <https://code.djangoproject.com/ticket/35996#comment:7>
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/01070193b75b36cc-b82ad043-8689-47fe-8492-a41c9e292d4e-000000%40eu-central-1.amazonses.com.