Fixed #25054 -- Added app_label to swapped model AttributeError

This commit is contained in:
Chris Lamb 2015-07-02 18:42:24 +01:00 committed by Tim Graham
parent 30a152a367
commit 61f3e22e38
2 changed files with 22 additions and 20 deletions

View File

@ -270,9 +270,13 @@ class SwappedManagerDescriptor(object):
self.model = model self.model = model
def __get__(self, instance, type=None): def __get__(self, instance, type=None):
raise AttributeError("Manager isn't available; %s has been swapped for '%s'" % ( raise AttributeError(
self.model._meta.object_name, self.model._meta.swapped "Manager isn't available; '%s.%s' has been swapped for '%s'" % (
)) self.model._meta.app_label,
self.model._meta.object_name,
self.model._meta.swapped,
)
)
class EmptyManager(Manager): class EmptyManager(Manager):

View File

@ -109,12 +109,12 @@ class ManagersRegressionTests(TestCase):
# Accessing the manager on a swappable model should # Accessing the manager on a swappable model should
# raise an attribute error with a helpful message # raise an attribute error with a helpful message
try: msg = (
"Manager isn't available; 'managers_regress.SwappableModel' "
"has been swapped for 'managers_regress.Parent'"
)
with self.assertRaisesMessage(AttributeError, msg):
SwappableModel.objects.all() SwappableModel.objects.all()
self.fail('Should raise an AttributeError')
except AttributeError as e:
self.assertEqual(str(e), "Manager isn't available; SwappableModel has been swapped for 'managers_regress.Parent'")
finally: finally:
apps.app_configs['managers_regress'].models = _old_models apps.app_configs['managers_regress'].models = _old_models
apps.all_models['managers_regress'] = _old_models apps.all_models['managers_regress'] = _old_models
@ -128,7 +128,6 @@ class ManagersRegressionTests(TestCase):
try: try:
class SwappableModel(models.Model): class SwappableModel(models.Model):
stuff = models.Manager() stuff = models.Manager()
class Meta: class Meta:
@ -137,12 +136,12 @@ class ManagersRegressionTests(TestCase):
# Accessing the manager on a swappable model with an # Accessing the manager on a swappable model with an
# explicit manager should raise an attribute error with a # explicit manager should raise an attribute error with a
# helpful message # helpful message
try: msg = (
"Manager isn't available; 'managers_regress.SwappableModel' "
"has been swapped for 'managers_regress.Parent'"
)
with self.assertRaisesMessage(AttributeError, msg):
SwappableModel.stuff.all() SwappableModel.stuff.all()
self.fail('Should raise an AttributeError')
except AttributeError as e:
self.assertEqual(str(e), "Manager isn't available; SwappableModel has been swapped for 'managers_regress.Parent'")
finally: finally:
apps.app_configs['managers_regress'].models = _old_models apps.app_configs['managers_regress'].models = _old_models
apps.all_models['managers_regress'] = _old_models apps.all_models['managers_regress'] = _old_models
@ -156,7 +155,6 @@ class ManagersRegressionTests(TestCase):
try: try:
class SwappableModel(models.Model): class SwappableModel(models.Model):
objects = models.Manager() objects = models.Manager()
class Meta: class Meta:
@ -165,12 +163,12 @@ class ManagersRegressionTests(TestCase):
# Accessing the manager on a swappable model with an # Accessing the manager on a swappable model with an
# explicit manager should raise an attribute error with a # explicit manager should raise an attribute error with a
# helpful message # helpful message
try: msg = (
"Manager isn't available; 'managers_regress.SwappableModel' "
"has been swapped for 'managers_regress.Parent'"
)
with self.assertRaisesMessage(AttributeError, msg):
SwappableModel.objects.all() SwappableModel.objects.all()
self.fail('Should raise an AttributeError')
except AttributeError as e:
self.assertEqual(str(e), "Manager isn't available; SwappableModel has been swapped for 'managers_regress.Parent'")
finally: finally:
apps.app_configs['managers_regress'].models = _old_models apps.app_configs['managers_regress'].models = _old_models
apps.all_models['managers_regress'] = _old_models apps.all_models['managers_regress'] = _old_models