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:
parent
30a152a367
commit
61f3e22e38
@ -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):
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user