Skip to content

Commit

Permalink
Fixed #19401 - swapped model check case insensitive
Browse files Browse the repository at this point in the history
with respect to the model class, not the app_label
  • Loading branch information
ptone committed Dec 15, 2012
1 parent 7eba5fb commit 5c7d036
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions django/contrib/auth/tests/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ def test_swappable_user(self):
with self.assertRaises(AttributeError):
User.objects.all()

@override_settings(AUTH_USER_MODEL='auth.user')
def test_swappable_user_case(self):
"The model name is not case sensitive"
self.assertEqual(User._meta.swapped, None)

@override_settings(AUTH_USER_MODEL='badsetting')
def test_swappable_user_bad_setting(self):
"The alternate user setting must point to something in the format app.model"
Expand Down
16 changes: 13 additions & 3 deletions django/db/models/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,20 @@ def _swapped(self):
name of the replacement; otherwise, return None.
"""
if self.swappable:
model_label = '%s.%s' % (self.app_label, self.object_name)
model_label = '%s.%s' % (self.app_label, self.object_name.lower())
swapped_for = getattr(settings, self.swappable, None)
if swapped_for not in (None, model_label):
return swapped_for
if swapped_for:
try:
swapped_label, swapped_object = swapped_for.split('.')
except ValueError:
# setting not in the format app_label.model_name
# raising ImproperlyConfigured here causes problems with
# test cleanup code - instead it is raised in get_user_model
return None

if '%s.%s' % (swapped_label, swapped_object.lower()) not in (
None, model_label ):
return swapped_for
return None
swapped = property(_swapped)

Expand Down

0 comments on commit 5c7d036

Please sign in to comment.