0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

Refs #24201 -- Ignored order_with_respect_to private fields in migrations.

Thanks Tim for the review.
This commit is contained in:
Simon Charette 2016-05-13 11:53:04 -04:00
parent 18900e55c5
commit c0118ff80b
2 changed files with 17 additions and 0 deletions

View File

@ -443,6 +443,9 @@ class ModelState(object):
for key in ["unique_together", "index_together", "order_with_respect_to"]: for key in ["unique_together", "index_together", "order_with_respect_to"]:
if key in options: if key in options:
del options[key] del options[key]
# Private fields are ignored, so remove options that refer to them.
elif options.get('order_with_respect_to') in {field.name for field in model._meta.private_fields}:
del options['order_with_respect_to']
def flatten_bases(model): def flatten_bases(model):
bases = [] bases = []

View File

@ -9,6 +9,7 @@ from django.db.migrations.state import (
ModelState, ProjectState, get_related_models_recursive, ModelState, ProjectState, get_related_models_recursive,
) )
from django.test import SimpleTestCase, override_settings from django.test import SimpleTestCase, override_settings
from django.test.utils import isolate_apps
from django.utils import six from django.utils import six
from .models import ( from .models import (
@ -911,6 +912,19 @@ class ModelStateTests(SimpleTestCase):
self.assertEqual([name for name, mgr in food_state.managers], ['food_mgr']) self.assertEqual([name for name, mgr in food_state.managers], ['food_mgr'])
self.assertEqual(food_state.managers[0][1].args, ('a', 'b', 1, 2)) self.assertEqual(food_state.managers[0][1].args, ('a', 'b', 1, 2))
@isolate_apps('migrations', 'django.contrib.contenttypes')
def test_order_with_respect_to_private_field(self):
class PrivateFieldModel(models.Model):
content_type = models.ForeignKey('contenttypes.ContentType', models.CASCADE)
object_id = models.PositiveIntegerField()
private = GenericForeignKey()
class Meta:
order_with_respect_to = 'private'
state = ModelState.from_model(PrivateFieldModel)
self.assertNotIn('order_with_respect_to', state.options)
class RelatedModelsTests(SimpleTestCase): class RelatedModelsTests(SimpleTestCase):