mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #19049 -- Ensure that swapped models aren't included in reverse field caches.
Thanks to Ivan Virabyan for the report.
This commit is contained in:
@@ -303,13 +303,28 @@ class SwappedModel(models.Model):
|
||||
References to this model *should* raise a validation error.
|
||||
Requires TEST_SWAPPED_MODEL to be defined in the test environment;
|
||||
this is guaranteed by the test runner using @override_settings.
|
||||
|
||||
The foreign keys and m2m relations on this model *shouldn't*
|
||||
install related accessors, so there shouldn't be clashes with
|
||||
the equivalent names on the replacement.
|
||||
"""
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
foreign = models.ForeignKey(Target, related_name='swappable_fk_set')
|
||||
m2m = models.ManyToManyField(Target, related_name='swappable_m2m_set')
|
||||
|
||||
class Meta:
|
||||
swappable = 'TEST_SWAPPED_MODEL'
|
||||
|
||||
|
||||
class ReplacementModel(models.Model):
|
||||
"""A replacement model for swapping purposes."""
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
foreign = models.ForeignKey(Target, related_name='swappable_fk_set')
|
||||
m2m = models.ManyToManyField(Target, related_name='swappable_m2m_set')
|
||||
|
||||
|
||||
class BadSwappableValue(models.Model):
|
||||
"""A model that can be swapped out; during testing, the swappable
|
||||
value is not of the format app.model
|
||||
|
||||
@@ -37,7 +37,7 @@ class InvalidModelTestCase(unittest.TestCase):
|
||||
# easier to set this up as an override than to require every developer
|
||||
# to specify a value in their test settings.
|
||||
@override_settings(
|
||||
TEST_SWAPPED_MODEL='invalid_models.Target',
|
||||
TEST_SWAPPED_MODEL='invalid_models.ReplacementModel',
|
||||
TEST_SWAPPED_MODEL_BAD_VALUE='not-a-model',
|
||||
TEST_SWAPPED_MODEL_BAD_MODEL='not_an_app.Target',
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user