Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: django/django
...
head fork: ptone/django
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 15, 2012
@ptone ptone Fixed #19401 - swapped model check case insensitive
with respect to the model class, not the app_label
5c7d036
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)

No commit comments for this range

Something went wrong with that request. Please try again.