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
I use the pattern of saving only fields that have changed in a model, as such:
obj.save(only=obj.dirty_fields)
However, if the dirty_fields value is an empty list, I would expect save() to save no fields (i.e., be a no-op.) Instead, it saves all the fields, which is counter-intuitive and can lead to problems if I don't explicitly check for an empty list.
Thanks, I've made the change as suggested (although it is if only is not None). Peewee is active-record so calling save with no data will raise a ValueError.
The issue
I use the pattern of saving only fields that have changed in a model, as such:
However, if the
dirty_fields
value is an empty list, I would expectsave()
to save no fields (i.e., be a no-op.) Instead, it saves all the fields, which is counter-intuitive and can lead to problems if I don't explicitly check for an empty list.I believe the issue is in the line below:
peewee/peewee.py
Line 6521 in ce9375c
Instead of checking the falseness of
only
, it might be more appropriate to check if it is None:The text was updated successfully, but these errors were encountered: