diff options
| author | Juan Alvarez <juan@sytex.io> | 2023-08-15 16:53:30 -0300 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-08-19 11:23:59 +0200 |
| commit | 46b2b08e4531012357dc359809588cbd61a38225 (patch) | |
| tree | 0833508625a9dce1b188ca7a07ac4259feb36b6e /django/core/serializers/python.py | |
| parent | d34db6602e89387ae9ddc9ae94defe5c838acb88 (diff) | |
[4.2.x] Fixed #34779 -- Avoided unnecessary selection of non-nullable m2m fields without natural keys during serialization.
By using `select_related(None)` instead of `select_related()`, the
unnecessary joins are completely avoided. Note that the current tests
already covers the change, when the field is not `null=True`.
Regression in f9936deed1ff13b20e18bd9ca2b0750b52706b6c.
Backport of 517d3bb4dd17e9c51690c98d747b86a0ed8b2fbf from main
Diffstat (limited to 'django/core/serializers/python.py')
| -rw-r--r-- | django/core/serializers/python.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py index 0dc504aa34..7ec894aa00 100644 --- a/django/core/serializers/python.py +++ b/django/core/serializers/python.py @@ -80,7 +80,10 @@ class Serializer(base.Serializer): def queryset_iterator(obj, field): return ( - getattr(obj, field.name).select_related().only("pk").iterator() + getattr(obj, field.name) + .select_related(None) + .only("pk") + .iterator() ) m2m_iter = getattr(obj, "_prefetched_objects_cache", {}).get( |
