Skip to content

Commit

Permalink
[1.9.x] Fixed #25560 -- Made empty string related_name invalid.
Browse files Browse the repository at this point in the history
Thanks to Ali Lotfi for the initial report and patch
and Tim Graham for the review.

Backport of c1b6a8a from master
  • Loading branch information
charettes authored and timgraham committed Oct 19, 2015
1 parent d8b2645 commit 3aeb84d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django/db/models/fields/related.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _check_related_name_is_valid(self):
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):
Expand Down
2 changes: 1 addition & 1 deletion django/db/models/fields/reverse_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):

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()
Expand Down
1 change: 1 addition & 0 deletions tests/invalid_models_tests/test_relative_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ def test_related_field_has_invalid_related_name(self):
'ends_with_whitespace_%s' % whitespace,
'with', # a Python keyword
'related_name\n',
'',
]
# Python 2 crashes on non-ASCII strings.
if six.PY3:
Expand Down

0 comments on commit 3aeb84d

Please sign in to comment.