Code

Ticket #3519: ticket3519.diff

File ticket3519.diff, 1.4 KB (added by dp_wiz, 7 years ago)

workaround

Line 
1Index: django/db/models/manipulators.py
2===================================================================
3--- django/db/models/manipulators.py    (revision 4537)
4+++ django/db/models/manipulators.py    (working copy)
5@@ -160,7 +160,7 @@
6                     # old to the new, to see which fields have changed.
7                     old_rel_obj = None
8                     if self.change:
9-                        if rel_new_data[related.opts.pk.name][0]:
10+                        if rel_new_data[related.opts.pk.name] and rel_new_data[related.opts.pk.name][0]:
11                             try:
12                                 old_rel_obj = getattr(self.original_object, related.get_accessor_name()).get(**{'%s__exact' % related.opts.pk.name: rel_new_data[related.opts.pk.attname][0]})
13                             except ObjectDoesNotExist:
14Index: django/db/models/fields/__init__.py
15===================================================================
16--- django/db/models/fields/__init__.py (revision 4537)
17+++ django/db/models/fields/__init__.py (working copy)
18@@ -284,7 +284,7 @@
19         Given the full new_data dictionary (from the manipulator), returns this
20         field's data.
21         """
22-        if rel:
23+        if rel and new_data.get(self.name, [self.get_default()]):
24             return new_data.get(self.name, [self.get_default()])[0]
25         val = new_data.get(self.name, self.get_default())
26         if not self.empty_strings_allowed and val == '' and self.null: