Don't overwrite modifications to ModificationTimestampField
Review Request #9816 — Created March 21, 2018 and submitted
Information | |
---|---|
brennie | |
Djblets | |
release-1.0.x | |
8800 | |
a0aee27... | |
Reviewers | |
djblets | |
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, … |
|
|
A bunch of work was done prior to this change on release-1.0.x of Djblets to clean up documentation and such. … |
|
|
This does exactly the same thing as django.utils.timezone.now() |
|
|
Can we add a blank line so this doesn't seem grouped with the comment about i18n? |
|
|
typo: ustom |
|
|
No blank line. |
|
|
This function isn't getting anything. It's returning something. |
|
|
, optional |
|
|
This has a lot of duplicate code paths. This would clear those up: existing_value = getattr(model, self.attnmae) if ((not add … |
|
|
This isn't the format we use for test class docstrings. |
|
|
Should be in alphabetical order. |
|
|
:py:meth: |
|
|
Same here. |
|
|
Can this be get_attr_name or maybe make_attr_name? |
|
|
Blank lines around this. |
|
|
This is in the wrong import group. |
|
|
You can just use timezone.utc. Actually, I think I pushed a change that already did this, so you'll just need … |
|
|
Does .objects.create() work for this, instead of doing a .save()? |
|
|
.objects.create() here and below. |
|
Description: |
|
---|
Change Summary:
Simplify unit tests
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 2 (+341 -14) |
Checks run (2 succeeded)
-
-
djblets/db/fields.py (Diff revision 2) This does exactly the same thing as
django.utils.timezone.now()
Change Summary:
Addressed David's issues. Now set USE_TZ in tests.
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 3 (+323 -17) |
Checks run (2 succeeded)
-
-
tests/settings.py (Diff revision 3) Can we add a blank line so this doesn't seem grouped with the comment about i18n?
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 4 (+324 -17) |
Checks run (2 succeeded)
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 5 (+324 -17) |
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.
-
-
djblets/db/fields.py (Diff revision 5) This function isn't getting anything. It's returning something.
-
-
djblets/db/fields.py (Diff revision 5) 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)
-
djblets/db/tests/test_modification_timestamp_field.py (Diff revision 5) This isn't the format we use for test class docstrings.
Change Summary:
Migrated to release-1.0.x
Branch: |
|
||||
---|---|---|---|---|---|
Commit: |
|
||||
Diff: |
Revision 6 (+258 -7) |
Checks run (2 succeeded)
-
-
djblets/db/fields/modification_timestamp_field.py (Diff revision 6) Should be in alphabetical order.
-
-
-
djblets/db/fields/modification_timestamp_field.py (Diff revision 6) Can this be
get_attr_name
or maybemake_attr_name
? -
-
djblets/db/tests/test_modification_timestamp_field.py (Diff revision 6) This is in the wrong import group.
-
djblets/db/tests/test_modification_timestamp_field.py (Diff revision 6) You can just use
timezone.utc
.Actually, I think I pushed a change that already did this, so you'll just need to update.
-
djblets/db/tests/test_modification_timestamp_field.py (Diff revision 6) Does
.objects.create()
work for this, instead of doing a.save()
? -
tests/settings.py (Diff revision 6) This was recently added as well, so you'll probably see this go away or conflict when you update.
Change Summary:
Addressed Christian's feedback.
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 7 (+253 -4) |
Checks run (2 succeeded)
-
-
djblets/db/tests/test_modification_timestamp_field.py (Diff revision 7) .objects.create()
here and below.
Change Summary:
Addressed Christian's feedback.
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 8 (+250 -4) |