mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Don't cache _readable_fields and _writable_fields (#6689)
It might be useful for a serializer with many many fields which uses read_only and write_only on a large percentage of the fields. But the memory usage and statefulness it adds are not worth it for the common case.
This commit is contained in:
parent
1b8141a4aa
commit
ccd9b71c0a
|
@ -361,18 +361,17 @@ class Serializer(BaseSerializer, metaclass=SerializerMetaclass):
|
|||
fields[key] = value
|
||||
return fields
|
||||
|
||||
@cached_property
|
||||
@property
|
||||
def _writable_fields(self):
|
||||
return [
|
||||
field for field in self.fields.values() if not field.read_only
|
||||
]
|
||||
for field in self.fields.values():
|
||||
if not field.read_only:
|
||||
yield field
|
||||
|
||||
@cached_property
|
||||
@property
|
||||
def _readable_fields(self):
|
||||
return [
|
||||
field for field in self.fields.values()
|
||||
if not field.write_only
|
||||
]
|
||||
for field in self.fields.values():
|
||||
if not field.write_only:
|
||||
yield field
|
||||
|
||||
def get_fields(self):
|
||||
"""
|
||||
|
|
|
@ -219,7 +219,7 @@ class TestReadOnly:
|
|||
Read-only fields should not be writable, even with default ()
|
||||
"""
|
||||
serializer = self.Serializer()
|
||||
assert len(serializer._writable_fields) == 1
|
||||
assert len(list(serializer._writable_fields)) == 1
|
||||
|
||||
def test_validate_read_only(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user