Closed nemesifier closed 4 years ago
Problem faced while implementing ondelta
:
_state.adding
value is always false
in the ondelta
functions.
def clean(self):
print(self._state.adding) # Output: True
...
def ondelta_[Field](self, old_value, new_value):
print(self._state.adding) # Output: False | [Expected: True]
...
To solve this, i created a new variable customStateAdding
in clean()
,
However if the ondelta()
is called before the clean()
the code breaks,
this might cause unintentional bugs.
in
Device.clean
andConfig.clean
we perform an extra query to understand if important fields are being changed and the configuration must be flagged as modified.We can optimize this and get rid of the extra query.
An option could be to use this third party module: https://github.com/adamhaney/django-ondelta If such an approach could work we could start using it in other openwisp modules as well.