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

How to handle auto_now=True fields? #195

Open
LincolnPuzey opened this issue Feb 28, 2022 · 2 comments
Open

How to handle auto_now=True fields? #195

LincolnPuzey opened this issue Feb 28, 2022 · 2 comments

Comments

@LincolnPuzey
Copy link
Collaborator

There have been two PRs (#152 and #194) suggesting some sort of change to the current behavior which is that:

a) Fields with auto_now=True do not appear as dirty - they won't appear in .get_dirty_fields()
b) And so by extension .save_dirtyfields() doesn't include them in update_fields so they are not updated by this method.

Some options we have are:

  1. Make no changes and document behavior. Users can override save() / save_dirty_fields() / get_dirty_fields() if they need something else.
  2. Keep (a) the same but make some change to save_dirty_fields. E.g. my suggestion here
  3. Make auto_now=True fields appear as dirty so save_dirtyfields() will update them.

There was a similar issue and discussion in Django here: https://code.djangoproject.com/ticket/22981 where the resolution was to make no changes.

@LincolnPuzey
Copy link
Collaborator Author

@romgar Do you have a strong preference for any option?

I think we should not change the behavior of (a). I would be open to doing something in save_dirty_fields() or not making any change at all.

@sidmitra
Copy link

sidmitra commented Mar 5, 2022

@LincolnPuzey 4th option could be to add a parameter? include_auto_now=True to save_dirty_fields() ? Your comment on the other PR also makes sense.

For the second part of your change - adding the option to save_dirty_fields(), rather than add a special case for auto_now fields, I think adding a generic extra_update_fields argument, eg

But perhaps Option 1 is also ok. We'll try it out and add comments here on any issues we encounter.

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