diff options
| author | Simon Charette <charette.s@gmail.com> | 2015-02-12 01:28:24 -0500 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2015-02-12 13:07:09 -0500 |
| commit | 9239f1dda7b94f53d21efb8b5e4d056e24f4e906 (patch) | |
| tree | 86b73b6f3aa9b6c1e32f7540f0b1a1272236f768 /tests | |
| parent | e519ee1d352e0e36fcb8edc9d33ec2845f663d3a (diff) | |
Refs #24215 -- Prevented pending lookup pollution by abstract models.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/model_fields/models.py | 11 | ||||
| -rw-r--r-- | tests/model_fields/tests.py | 44 |
2 files changed, 50 insertions, 5 deletions
diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py index 40499b0f8c..746071c916 100644 --- a/tests/model_fields/models.py +++ b/tests/model_fields/models.py @@ -367,3 +367,14 @@ class NullableUUIDModel(models.Model): class PrimaryKeyUUIDModel(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4) + + +############################################################################### + +# See ticket #24215. +class AbstractForeignFieldsModel(models.Model): + fk = models.ForeignKey('missing.FK') + m2m = models.ManyToManyField('missing.M2M', through='missing.Through') + + class Meta: + abstract = True diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index 8894ef9158..379d9e8b52 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -21,11 +21,12 @@ from django.utils import six from django.utils.functional import lazy from .models import ( - Bar, BigD, BigIntegerModel, BigS, BooleanModel, DataModel, DateTimeModel, - Document, FksToBooleans, FkToChar, FloatModel, Foo, GenericIPAddress, - IntegerModel, NullBooleanModel, PositiveIntegerModel, - PositiveSmallIntegerModel, Post, PrimaryKeyCharModel, RenamedField, - SmallIntegerModel, VerboseNameField, Whiz, WhizIter, WhizIterEmpty, + AbstractForeignFieldsModel, Bar, BigD, BigIntegerModel, BigS, BooleanModel, + DataModel, DateTimeModel, Document, FksToBooleans, FkToChar, FloatModel, + Foo, GenericIPAddress, IntegerModel, NullBooleanModel, + PositiveIntegerModel, PositiveSmallIntegerModel, Post, PrimaryKeyCharModel, + RenamedField, SmallIntegerModel, VerboseNameField, Whiz, WhizIter, + WhizIterEmpty, ) @@ -201,6 +202,39 @@ class ForeignKeyTests(test.TestCase): rel_name = Bar._meta.get_field('a').rel.related_name self.assertIsInstance(rel_name, six.text_type) + def test_abstract_model_pending_lookups(self): + """ + Foreign key fields declared on abstract models should not add lazy relations to + resolve relationship declared as string. refs #24215 + """ + opts = AbstractForeignFieldsModel._meta + to_key = ('missing', 'FK') + fk_lookup = (AbstractForeignFieldsModel, opts.get_field('fk')) + self.assertFalse( + any(lookup[0:2] == fk_lookup for lookup in opts.apps._pending_lookups.get(to_key, [])), + 'Pending lookup added for the abstract model foreign key `to` parameter' + ) + + +class ManyToManyFieldTests(test.TestCase): + def test_abstract_model_pending_lookups(self): + """ + Many-to-many fields declared on abstract models should not add lazy relations to + resolve relationship declared as string. refs #24215 + """ + opts = AbstractForeignFieldsModel._meta + to_key = ('missing', 'M2M') + fk_lookup = (AbstractForeignFieldsModel, opts.get_field('m2m')) + self.assertFalse( + any(lookup[0:2] == fk_lookup for lookup in opts.apps._pending_lookups.get(to_key, [])), + 'Pending lookup added for the abstract model many-to-many `to` parameter.' + ) + through_key = ('missing', 'Through') + self.assertFalse( + any(lookup[0:2] == fk_lookup for lookup in opts.apps._pending_lookups.get(through_key, [])), + 'Pending lookup added for the abstract model many-to-many `through` parameter.' + ) + class DateTimeFieldTests(unittest.TestCase): def test_datetimefield_to_python_usecs(self): |
