mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #24591 -- Optimized cloning of ModelState objects.
Changed ModelState.clone() to create a shallow copy of self.fields and self.managers.
This commit is contained in:
committed by
Tim Graham
parent
c331eeb89c
commit
1a1f16d67d
@@ -10,6 +10,7 @@ from django.test import SimpleTestCase, TestCase, override_settings
|
||||
|
||||
from .models import (
|
||||
FoodManager, FoodQuerySet, ModelWithCustomBase, NoMigrationFoodManager,
|
||||
UnicodeModel,
|
||||
)
|
||||
|
||||
|
||||
@@ -695,6 +696,21 @@ class ModelStateTests(TestCase):
|
||||
'ModelState.fields cannot be bound to a model - "field" is.'):
|
||||
ModelState('app', 'Model', [('field', field)])
|
||||
|
||||
def test_sanity_check_to(self):
|
||||
field = models.ForeignKey(UnicodeModel)
|
||||
with self.assertRaisesMessage(ValueError,
|
||||
'ModelState.fields cannot refer to a model class - "field.to" does. '
|
||||
'Use a string reference instead.'):
|
||||
ModelState('app', 'Model', [('field', field)])
|
||||
|
||||
def test_sanity_check_through(self):
|
||||
field = models.ManyToManyField('UnicodeModel')
|
||||
field.remote_field.through = UnicodeModel
|
||||
with self.assertRaisesMessage(ValueError,
|
||||
'ModelState.fields cannot refer to a model class - "field.through" does. '
|
||||
'Use a string reference instead.'):
|
||||
ModelState('app', 'Model', [('field', field)])
|
||||
|
||||
def test_fields_immutability(self):
|
||||
"""
|
||||
Tests that rendering a model state doesn't alter its internal fields.
|
||||
|
||||
Reference in New Issue
Block a user