Kaydet (Commit) c1b6a8a9 authored tarafından Simon Charette's avatar Simon Charette

Fixed #25560 -- Made empty string related_name invalid.

Thanks to Ali Lotfi for the initial report and patch
and Tim Graham for the review.
üst 4dcc2a19
......@@ -122,7 +122,7 @@ class RelatedField(Field):
import re
import keyword
related_name = self.remote_field.related_name
if not related_name:
if related_name is None:
return []
is_valid_id = True
if keyword.iskeyword(related_name):
......
......@@ -154,7 +154,7 @@ class ForeignObjectRel(object):
def is_hidden(self):
"Should the related object be hidden?"
return self.related_name is not None and self.related_name[-1] == '+'
return bool(self.related_name) and self.related_name[-1] == '+'
def get_joining_columns(self):
return self.field.get_reverse_joining_columns()
......
......@@ -662,6 +662,7 @@ class RelativeFieldTests(IsolatedModelsTestCase):
'ends_with_whitespace_%s' % whitespace,
'with', # a Python keyword
'related_name\n',
'',
]
# Python 2 crashes on non-ASCII strings.
if six.PY3:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment