question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Curious on why model.save(only=model.dirty_fields) isn't default behavior

See original GitHub issue

This 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:closed
  • Created 8 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
coleifercommented, Jul 2, 2015

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 own save() 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.

0reactions
shoncommented, Oct 16, 2015

Awesome. Thank you so much @coleifer

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why doesn't Django's Model.save() save only the dirty fields ...
save () will update all fields by default, which can introduce a lot of race conditions. If it update only the dirty fields,...
Read more >
Advanced Usage — django-dirtyfields 1.9.0 documentation
By default, when you use get_dirty_fields() function, if there are dirty fields, only the saved value is returned. You can use the verbose...
Read more >
How to save changed fields with ModelForm? - Stack Overflow
Currently the form is showing the current values from database, but isn't saving changed data. form.is_valid() returns True, but form.save() ...
Read more >
Add a way to track whether a revision was default ... - Drupal
A new method RevisionLogInterface::wasDefaultRevision() has been added, returning the revision default status when it was stored. Data model ...
Read more >
Where to put bussiness logic for object instantiation in django?
from django.db import models class Trip(models. ... Or you could save a step and just call is_valid() on a Form or Serializer.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found