diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-15 19:10:36 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-15 19:10:36 +0100 |
commit | 0d726e6eeed7bd696c0e7e0b973519d136f88c10 (patch) | |
tree | e3f75eda3ac7120aff69781a3fd4e50d7ab4bfba | |
parent | 04b76c34eacbd9ca39e4d4f61c7c57adf6412107 (diff) | |
download | Ishtar-0d726e6eeed7bd696c0e7e0b973519d136f88c10.tar.bz2 Ishtar-0d726e6eeed7bd696c0e7e0b973519d136f88c10.zip |
Fix m2m history save when no previous history have been recorded
-rw-r--r-- | archaeological_files/tests.py | 7 | ||||
-rw-r--r-- | ishtar_common/utils.py | 11 |
2 files changed, 12 insertions, 6 deletions
diff --git a/archaeological_files/tests.py b/archaeological_files/tests.py index 312204a14..ef6c5ad74 100644 --- a/archaeological_files/tests.py +++ b/archaeological_files/tests.py @@ -139,7 +139,12 @@ class FileTest(TestCase, FileInit): for k in initial_values.keys(): if k == 'last_modified': continue - self.assertTrue(k in new_values) + elif k == 'history_m2m' and not initial_values[k]: + initial_values[k] = dict( + [(j, []) for j in models.File.HISTORICAL_M2M] + ) + self.assertTrue(k in new_values, + msg=u'%s not in new values' % k) self.assertEqual( new_values[k], initial_values[k], msg=u"for %s: %s != %s" % (k, unicode(new_values[k]), diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index ba77a07e4..cbc7d069d 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -949,11 +949,12 @@ def m2m_historization_changed(sender, **kwargs): q = obj.history.filter( history_modifier_id=obj.history_modifier_id, ).order_by('-history_date', '-history_id') - hist = q.all()[0] - hist.history_m2m = hist_values - hist.history_date = hist.last_modified = datetime.datetime.now() - hist.save() - obj.skip_history_when_saving = True + if q.count(): + hist = q.all()[0] + hist.history_m2m = hist_values + hist.history_date = hist.last_modified = datetime.datetime.now() + hist.save() + obj.skip_history_when_saving = True elif not obj.history_modifier: obj.skip_history_when_saving = True obj.save() |