You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling setattr with None value does internally store that None in self._data, but later calls of getattr does not return None, but previous version of the field. This is quite unexpected as you would assume that getattr after successful setattr will return the same value.
In code, see implementation of __setattr__ in BaseDocument:
# Handle None values for required fields
if value is None and name in getattr(self, '_fields', {}):
self._data[name] = value
if hasattr(self, '_changed_fields'):
self._mark_as_changed(name)
return
So if value is None, then self._data is set, but after that return is invoked. So program flow does not get to:
Calling
setattr
withNone
value does internally store thatNone
inself._data
, but later calls ofgetattr
does not return None, but previous version of the field. This is quite unexpected as you would assume thatgetattr
after successfulsetattr
will return the same value.In code, see implementation of
__setattr__
inBaseDocument
:So if
value
isNone
, thenself._data
is set, but after thatreturn
is invoked. So program flow does not get to:So calling later on
getattr
for the same field returns old value.The text was updated successfully, but these errors were encountered: