django-simple-history
django-simple-history copied to clipboard
Documented auto_now usage with bulk_update_with_history
Description
When using bulk_update_with_history, a DateTimeField using auto_now doesn't automatically update like it does with Model.save()
This PR documents the issue under "Common Issues" and offers a convention-based solution
Related Issue
https://github.com/jazzband/django-simple-history/issues/1054
Motivation and Context
The motivation is to spread awareness of the issue and guide people towards a solution. It seems like a rather quiet bug that can really hurt data accuracy.
How Has This Been Tested?
The code is excerpts from our code
Screenshots (if appropriate):
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
Checklist:
- [x] I have run the
pre-commit runcommand to format and lint. - [x] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
- [x] I have read the CONTRIBUTING document.
- [x] I have added tests to cover my changes.
- [x] I have added my name and/or github handle to
AUTHORS.rst - [x] I have added my change to
CHANGES.rst - [x] All new and existing tests passed.
Codecov Report
Merging #1055 (dd38fb0) into master (6d09c3e) will not change coverage. The diff coverage is
n/a.
@@ Coverage Diff @@
## master #1055 +/- ##
=======================================
Coverage 97.23% 97.23%
=======================================
Files 23 23
Lines 1231 1231
Branches 199 199
=======================================
Hits 1197 1197
Misses 16 16
Partials 18 18
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
@twolfson what's the point? Don't you already have those auto_now dates on the history objects? I've traditionally ignored updated/created columns from my base model in my historical model
I think there's 2 ways to interpret your response so I'll respond to both:
- Why do you need an
updated_atcolumn on your normal model? (this is the fix I'm proposing to document)- This is a great question!
- It's not used in application code so much, but it's very useful to avoid looking at extra pages or doing complex joins when looking into issues
- Why does the historical model need an
updated_atcolumn?- It doesn't but this issue isn't about that. It's about the first one -- when using
bulk_update_with_history, we want to automatically update theauto_nowcolumn on the normal model - Arguably this isn't
django-simple-historyresponsibility, but that's why it's only being proposed as documentation, not as a code-based solution
- It doesn't but this issue isn't about that. It's about the first one -- when using