mirror of https://github.com/django/django.git
Fixed #32812 -- Restored immutability of named values from QuerySet.values_list().
Regression in 981a072dd4
.
Thanks pirelle for the report.
This commit is contained in:
parent
f10c52afab
commit
0393b9262d
|
@ -45,4 +45,8 @@ def create_namedtuple_class(*names):
|
|||
def __reduce__(self):
|
||||
return unpickle_named_row, (names, tuple(self))
|
||||
|
||||
return type('Row', (namedtuple('Row', names),), {'__reduce__': __reduce__})
|
||||
return type(
|
||||
'Row',
|
||||
(namedtuple('Row', names),),
|
||||
{'__reduce__': __reduce__, '__slots__': ()},
|
||||
)
|
||||
|
|
|
@ -9,4 +9,6 @@ Django 3.2.5 fixes several bugs in 3.2.4.
|
|||
Bugfixes
|
||||
========
|
||||
|
||||
* ...
|
||||
* Fixed a regression in Django 3.2 that caused a crash of
|
||||
``QuerySet.values_list(…, named=True)`` after ``prefetch_related()``
|
||||
(:ticket:`32812`).
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
from django.db.models.utils import create_namedtuple_class
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
|
||||
class NamedTupleClassTests(SimpleTestCase):
|
||||
def test_immutability(self):
|
||||
row_class = create_namedtuple_class('field1', 'field2')
|
||||
row = row_class('value1', 'value2')
|
||||
with self.assertRaises(AttributeError):
|
||||
row.field3 = 'value3'
|
|
@ -309,6 +309,13 @@ class PrefetchRelatedTests(TestDataMixin, TestCase):
|
|||
list(Book.objects.prefetch_related(relation))
|
||||
self.assertEqual(add_q_mock.call_count, 1)
|
||||
|
||||
def test_named_values_list(self):
|
||||
qs = Author.objects.prefetch_related('books')
|
||||
self.assertCountEqual(
|
||||
[value.name for value in qs.values_list('name', named=True)],
|
||||
['Anne', 'Charlotte', 'Emily', 'Jane'],
|
||||
)
|
||||
|
||||
|
||||
class RawQuerySetTests(TestDataMixin, TestCase):
|
||||
def test_basic(self):
|
||||
|
|
Loading…
Reference in New Issue