Fixed #7530, #7716 -- When using select_related() and encountering a NULL

related object, populate the attribute correctly. Patch from Bastien Kleineidam.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8098 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2008-07-27 01:18:23 +00:00
parent aee55ce524
commit f48855178d
2 changed files with 14 additions and 10 deletions

View file

@ -785,7 +785,11 @@ def get_cached_row(klass, row, index_start, max_depth=0, cur_depth=0,
restricted = requested is not None
index_end = index_start + len(klass._meta.fields)
obj = klass(*row[index_start:index_end])
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)
for f in klass._meta.fields:
if not select_related_descend(f, restricted, requested):
continue