Curious on why model.save(only=model.dirty_fields) isn't default behavior
See original GitHub issueThis definitely isn’t an issue, I was just curious on this design decision.
Why isn’t the default behavior to only update modified fields? (i.e. the behavior we get when using model.save(only=model.dirty_fields)
When viewing SQL logs, it’s much easier to see what’s being updated. If I update a single field, then the UPDATE
query reflects that. But if all fields are persisted then it’s more difficult to see what changed. Though as a counterpoint. it’s easer to see what the exact value of a row is after any given UPDATE
query if we explicitly re-set all fields.
Also, for extremely large rows, you’d be transferring less data if only updating modified fields.
Obviously it’s easy to implement this behavior, but just wondering why it’s not the default case.
Thanks! peewee is excellent
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Peewee is active record, the behavior is Django-like, so save() will save everything by default. Changing that now would probably break existing implementations anyways.
You can always subclass
Model
and add your ownsave()
implementation that does what you want.But to answer your question, mostly it is this way because that is how Django’s ORM behaves and I originally based peewee off of that. I can’t change it now because I’d worry about breaking people’s code.
Awesome. Thank you so much @coleifer