Remove redundant double getattr check

This commit is contained in:
Ruslan Chernenko 2022-11-03 20:39:21 +03:00 committed by GitHub
parent 1142ee5fc1
commit 2486dbf791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -250,13 +250,13 @@ class BaseSerializer(Field):
)
raise AssertionError(msg)
if not hasattr(self, '_data'):
if self.instance is not None and not getattr(self, '_errors', None):
if not hasattr(self, '_data') and not getattr(self, '_errors', None):
if self.instance is not None:
self._data = self.to_representation(self.instance)
elif hasattr(self, '_validated_data') and not getattr(self, '_errors', None):
elif hasattr(self, '_validated_data'):
self._data = self.to_representation(self.validated_data)
else:
self._data = self.get_initial()
else:
self._data = self.get_initial()
return self._data
@property