1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

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
def __get__(self, instance, type=None):
raise AttributeError("Manager isn't available; %s has been swapped for '%s'" % (
self.model._meta.object_name, self.model._meta.swapped
))
raise AttributeError(
"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):

View File

@ -109,12 +109,12 @@ class ManagersRegressionTests(TestCase):
# Accessing the manager on a swappable model should
# 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()
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:
apps.app_configs['managers_regress'].models = _old_models
apps.all_models['managers_regress'] = _old_models
@ -128,7 +128,6 @@ class ManagersRegressionTests(TestCase):
try:
class SwappableModel(models.Model):
stuff = models.Manager()
class Meta:
@ -137,12 +136,12 @@ class ManagersRegressionTests(TestCase):
# Accessing the manager on a swappable model with an
# explicit manager should 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.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:
apps.app_configs['managers_regress'].models = _old_models
apps.all_models['managers_regress'] = _old_models
@ -156,7 +155,6 @@ class ManagersRegressionTests(TestCase):
try:
class SwappableModel(models.Model):
objects = models.Manager()
class Meta:
@ -165,12 +163,12 @@ class ManagersRegressionTests(TestCase):
# Accessing the manager on a swappable model with an
# explicit manager should 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()
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:
apps.app_configs['managers_regress'].models = _old_models
apps.all_models['managers_regress'] = _old_models