Skip to content

Commit fda116e

Browse files
committed
Reset state on refresh_from_db calls
1 parent 38d79a2 commit fda116e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/dirtyfields/dirtyfields.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def __init__(self, *args, **kwargs):
2929
self._connect_m2m_relations()
3030
reset_state(sender=self.__class__, instance=self)
3131

32+
def refresh_from_db(self, *a, **kw):
33+
super(DirtyFieldsMixin, self).refresh_from_db(*a, **kw)
34+
reset_state(sender=self.__class__, instance=self)
35+
3236
def _connect_m2m_relations(self):
3337
for m2m_field, model in get_m2m_with_model(self.__class__):
3438
m2m_changed.connect(

tests/test_core.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,14 @@ def test_verbose_mode_on_adding():
162162
'boolean': {'saved': None, 'current': True},
163163
'characters': {'saved': None, 'current': u''}
164164
}
165+
166+
167+
@pytest.mark.django_db
168+
def test_refresh_from_db():
169+
tm = TestModel.objects.create()
170+
alias = TestModel.objects.get(pk=tm.pk)
171+
alias.boolean = False
172+
alias.save()
173+
174+
tm.refresh_from_db()
175+
assert tm.get_dirty_fields() == {}

0 commit comments

Comments
 (0)