From 19046db4f8511205a0b017a5d39f9a727395edac Mon Sep 17 00:00:00 2001 From: Luke Hodkinson Date: Mon, 30 Apr 2018 12:10:36 +1000 Subject: [PATCH] Throw an error when using missing field in `previous` --- model_utils/tracker.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/model_utils/tracker.py b/model_utils/tracker.py index 93e4a5db..83dc8fcc 100644 --- a/model_utils/tracker.py +++ b/model_utils/tracker.py @@ -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: - 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)"""