Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving only no fields saves all fields. #2269

Closed
arel opened this issue Sep 16, 2020 · 1 comment
Closed

Saving only no fields saves all fields. #2269

arel opened this issue Sep 16, 2020 · 1 comment

Comments

@arel
Copy link

arel commented Sep 16, 2020

The issue

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.

I believe the issue is in the line below:

peewee/peewee.py

Line 6521 in ce9375c

if only:

Instead of checking the falseness of only, it might be more appropriate to check if it is None:

 if only is None:
    ...
@coleifer
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants