Permalink
Browse files

Fixed #19401 - swapped model check case insensitive

with respect to the model class, not the app_label
  • Loading branch information...
1 parent 7eba5fb commit 5c7d036f431ee5a07574b670888f6d6fb4f49520 @ptone committed Dec 15, 2012
Showing with 18 additions and 3 deletions.
  1. +5 −0 django/contrib/auth/tests/basic.py
  2. +13 −3 django/db/models/options.py
View
5 django/contrib/auth/tests/basic.py
@@ -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"
View
16 django/db/models/options.py
@@ -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)

0 comments on commit 5c7d036

Please sign in to comment.