Skip to content
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

Throw an error in FieldTracker when using untracked field with .previous #324

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions model_utils/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ def current(self, fields=None):

def has_changed(self, field):
"""Returns ``True`` if field has changed from currently saved value"""
if field in self.fields:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@furious-luke shall we keep the if in both methods? Can you add a test for your change?

return self.previous(field) != self.get_field_value(field)
else:
raise FieldError('field "%s" not tracked' % field)
return self.previous(field) != self.get_field_value(field)

def previous(self, field):
"""Returns currently saved value of given field"""
return self.saved_data.get(field)
if field in self.fields:
return self.saved_data.get(field)
else:
raise FieldError('field "%s" not tracked' % field)

def changed(self):
"""Returns dict of fields that changed since save (with old values)"""
Expand Down