-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
master: Updated Diff to Catch TypeError #166
base: master
Are you sure you want to change the base?
Conversation
Thanks for the PR! We generally maintain 100% line and branch test coverage; would you be willing to add a test to the PR that exercises this addition? |
Yes, but it'll be a bit, I'm up to my ears in work. Sorry for any delay, but will do ASAP and pass another PR. Presuming it's in TimeFramedModelTests? Just glancing at the code, I can also create another class or use another if that's better. |
The fix is to FieldTracker, so the test would go with the rest of the FieldTracker tests. No need for a new PR, you can just add a new commit to this one (by pushing it to the same branch.) |
Just as an FYI, was working on the tests, and there is some recursive test method thing happening that my tiny little brain can't get around... ======================================================================
FAIL: test_post_save_previous (model_utils.tests.tests.InheritedModelTrackerTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/amadsen/html/sites/django-model-utils/model_utils/tests/tests.py", line 1438, in test_post_save_previous
self.assertPrevious(name='retro', number=4, mutable=[1,2,3], date=testdate)
File "/home/amadsen/html/sites/django-model-utils/model_utils/tests/tests.py", line 1334, in assertPrevious
self.assertEqual(tracker.previous(field), value)
AssertionError: None != datetime.datetime(2001, 12, 1, 1, 0) But then later: ======================================================================
FAIL: test_post_save_previous (model_utils.tests.tests.InheritedFieldTrackerTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/amadsen/html/sites/django-model-utils/model_utils/tests/tests.py", line 1438, in test_post_save_previous
self.assertPrevious(name='retro', number=4, mutable=[1,2,3], date=None)
File "/home/amadsen/html/sites/django-model-utils/model_utils/tests/tests.py", line 1334, in assertPrevious
self.assertEqual(tracker.previous(field), value)
AssertionError: datetime.datetime(2001, 12, 1, 1, 0) != None So not sure my tests are gonna get committed too soon, only because I can't understand where this method is coming from twice, with different params. |
Some tests are run multiple times under different conditions by inheriting It's a cheap way to "parametrize" tests, reusing the same test under slightly different conditions to improve the overall coverage of the test suite. Does that help clarify? |
Yes, that's helpful. I must have missed the InheritedFieldTrackerTests and ModelTrackerTests. Sorry for all the back and forth, you must be hating this pull request by now :) But removing those (for now) did the trick, so back in bizness. Oh, and one additional sidenote, this may not matter, but for me the PassThroughManager test raises a PicklingError, which I'll assume is something with my build so I'm ignoring for now. PicklingError: Can't pickle <class 'model_utils.managers._PassThroughManager'>: it's not found as model_utils.managers._PassThroughManager |
Not at all, I appreciate you sticking with it! Hmm, the PicklingError is odd. Yeah, ignore it for now and we'll see if it pops up anywhere else (e.g. on Travis CI). |
Added native, then TZ, aware "date" field to tests. Note, I had not earlier modified the ModelInstanceTracker, so pay special attention to this: Felt bad writing it, but had to insert the exception somehow :) |
The change to So I guess we should have talked a bit more about how to implement this test. I see that you probably ran across this issue in the context of datetimes (naive vs tz-aware), but really the change isn't inherently related to datetimes, and using datetimes in the tests makes the test changes much more invasive than I'd prefer (including a new dependence on pytz, which I'd rather not introduce, and which will cause the Travis CI run to fail). Really all that's needed to trigger this new code-path is any object that raises a
So I think the test for this can be written much more simply without needing to introduce the new Sorry to ask you to make this change after all the work you did on the datetime-using approach :/ |
@@ -172,8 +175,16 @@ def changed(self): | |||
return {} | |||
saved = self.saved_data.items() | |||
current = self.current() | |||
return dict((k, v) for k, v in saved if v != current[k]) | |||
|
|||
dict = {} |
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.
Let's not use dict
as a variable name and shadow the built-in dict
constructor. Something like data
would be better.
try: | ||
return self.previous(field) != self.get_field_value(field) | ||
except TypeError: | ||
return True |
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.
In our current issue situation, it will mask the TypeError
, which will be even harder to detect. I think we should properly handle timezone related issues.
@Goldcap quite old MR, are you still interested to work on it? |
@romgar Sorry, I dropped the ball on this one. I think we should probably close this out at this point. |
No problem, I completely understand. I will probably dive into it at some point:-) |
I see an interesting feature here. @romgar do you feel like I should try to rebase it and fix the tests? |
You can definitely have a look @Natim if you are interested. I don't have much time these days to work on this anymore. |
Added a TypeError exception, really from here:
#150
Lhanks for the code! Super handy :)