mtre...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed c54ba79

Fixed #8036 -- Fixed a case when attempting to traverse non-existent related
instances. We weren't skipping the correct output columns before processing
subsequent existing related instances. Thanks to mrmachine for the test case.

  • Participants
  • Parent commits 85bc4d4

Comments (0)

Files changed (2)

File django/db/models/

     fields = row[index_start:index_end]
     if not [x for x in fields if x is not None]:
         # If we only have a list of Nones, there was not related object.
-        return None, index_end
-    obj = klass(*fields)
+        obj = None
+    else:
+        obj = klass(*fields)
     for f in klass._meta.fields:
         if not select_related_descend(f, restricted, requested):
                 cur_depth+1, next)
         if cached_row:
             rel_obj, index_end = cached_row
-            setattr(obj, f.get_cache_name(), rel_obj)
+            if obj is not None:
+                setattr(obj, f.get_cache_name(), rel_obj)
     return obj, index_end