-
-
Notifications
You must be signed in to change notification settings - Fork 361
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
Create new FieldTracker that works well with foreign keys #52
Conversation
I'm not sure whether it's overkill to duplicate all |
self.fields = fields | ||
self.field_map = field_map | ||
|
||
def get_field(self, field): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be named something like get_field_value
instead, since that's what it returns, not a Field
object.
Looks good! Made a few comments. Regarding the tests, I would probably be inclined to cut out all the Also, this PR will need documentation updates before it's merged. I'd handle the docs similarly to the code; change the main documentation to refer entirely to |
Return None values instead of an empty dict
The FieldTracker has_changed method no longer returns True for any input when the instance is unsaved and no longer raises a FieldError for fields after the first save. The original ModelTracker behavior is maintained.
@carljm I believe I've taken all of your feedback so far into account at this point. Still to do:
|
|
||
def test_first_save(self): | ||
def test_pre_save_changed(self): | ||
self.assertChanged(name=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little odd to me, but I'm not sure how we could fix this in a general way.
What's going on here:
# default values
assert self.instance.name == ''
assert self.instance.number is None
# previous values default to None for new instance
assert self.instance.tracker.previous('name') is None
assert self.instance.tracker.previous('number') is None
# '' != None
assert self.instance.tracker.has_changed('name')
# None == None
assert not self.instance.tracker.has_changed('number')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is actually fine. I think the most important thing is to be clear about what the invariants are, and be consistent: e.g. that an unsaved instance is considered to have None
for all previous()
field values, and has_changed
simply compares previous()
with the current attribute value.
Looking good! A couple quick notes on the tests; these don't need to block this PR (especially since they pre-date it), but things to consider in the future:
|
I agree. The Django 1.5 check should be refactored into a separate test with a skipIf.
I agree. This is especially confusing in the current tests because I've used |
Odd, the comments about I hadn't thought of the tracking-non-fields use case. If you add a test for that, I'm fine with your implementation of |
Besides the minor doc additions I just mentioned, is this waiting for anything else? |
Feel free to add both of those notes to the branch if you have a particular
|
* master: Remove misinformation from changelog; oops. Tweak AUTHORS and changelog. PassThroughManager calls superclass `get_query_set`. Update AUTHORS and changelog. Fix tox.ini so runtests.sh works. Test and fix for second grandchild bug.
Ok, doc updates pushed. If you're willing, please review my summary of the differences between |
The differences listed in the README note look good to me. I just added the missing tests for tracking a non-field model attribute. Those tests fail right now because |
I fixed the rounding issue. This should be good to merge now. |
This will fix the issue mentioned in #43.