Don't overwrite modifications to ModificationTimestampField
Review Request #9816 — Created March 21, 2018 and submitted
The ModificationTimestampField now tracks manual modifications to the
value so that if code manually sets a timestamp it will not be
overwritten during model save. This allows models to manage timestamps
manually in some cases without having to resort to mucking about with
save_base
, etc.
Ran unit tests.
Description | From | Last Updated |
---|---|---|
There's also a bunch of unit tests in release-1.0.x that you're probably going to want to bring over. In fact, … |
chipx86 | |
A bunch of work was done prior to this change on release-1.0.x of Djblets to clean up documentation and such. … |
chipx86 | |
This does exactly the same thing as django.utils.timezone.now() |
david | |
Can we add a blank line so this doesn't seem grouped with the comment about i18n? |
david | |
typo: ustom |
david | |
No blank line. |
chipx86 | |
This function isn't getting anything. It's returning something. |
chipx86 | |
, optional |
chipx86 | |
This has a lot of duplicate code paths. This would clear those up: existing_value = getattr(model, self.attnmae) if ((not add … |
chipx86 | |
This isn't the format we use for test class docstrings. |
chipx86 | |
Should be in alphabetical order. |
chipx86 | |
:py:meth: |
chipx86 | |
Same here. |
chipx86 | |
Can this be get_attr_name or maybe make_attr_name? |
chipx86 | |
Blank lines around this. |
chipx86 | |
This is in the wrong import group. |
chipx86 | |
You can just use timezone.utc. Actually, I think I pushed a change that already did this, so you'll just need … |
chipx86 | |
Does .objects.create() work for this, instead of doing a .save()? |
chipx86 | |
.objects.create() here and below. |
chipx86 |
- Description:
-
The ModificationTimestampField now tracks manual modifications to the
value so that if code manually sets a timestamp it will not be overwritten during model save. This allows models to manage timestamps manually in some cases without having to resort to mucking about with ~ save_raw
etc.~ save_base
, etc.
- Change Summary:
-
Simplify unit tests
- Commit:
-
cc35cf8f53064dacd162d48d24b532081e2ef529515acbc161447a74b8d23fd3b7743beb9048c60c
Checks run (2 succeeded)
- Change Summary:
-
Addressed David's issues. Now set USE_TZ in tests.
- Commit:
-
515acbc161447a74b8d23fd3b7743beb9048c60c357f2a52319c8110e2ec094dcf791787acbe0c60
Checks run (2 succeeded)
- Commit:
-
357f2a52319c8110e2ec094dcf791787acbe0c609ede2d0b7fd3ae7ce1e845925743d81d96a8e162
Checks run (2 succeeded)
- Commit:
-
9ede2d0b7fd3ae7ce1e845925743d81d96a8e16228c4496226b4e4c5fb5682623f2453dce548fb2a
Checks run (2 succeeded)
-
-
There's also a bunch of unit tests in release-1.0.x that you're probably going to want to bring over.
In fact, what I'd suggest is having a precursor change that ports those unit tests to release-0.9.x and ports the docstrings. This change can then be based on those. As it is, it's right now going to be a bit of a mess trying to merge the branches without that work.
-
-
-
-
This has a lot of duplicate code paths. This would clear those up:
existing_value = getattr(model, self.attnmae) if ((not add and not state.modified) or (add and existing_value is None)): value = timezone.now() setattr(model, self.attname, value) elif ((not add and state.modified) or (add and existing_value is not None)): value = super(...).pre_save(model, add)
-
- Change Summary:
-
Migrated to release-1.0.x
- Branch:
-
release-0.9.xrelease-1.0.x
- Commit:
-
28c4496226b4e4c5fb5682623f2453dce548fb2a3f65633cf7379a216d23ceb20d5de62a662b971a
Checks run (2 succeeded)
- Change Summary:
-
Addressed Christian's feedback.
- Commit:
-
3f65633cf7379a216d23ceb20d5de62a662b971aa91a504b00abe5b339258d8948b1d30c278381b3