mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #27279 -- Fixed a migration performance regression related to RenameModel operations.
Thanks Trac alias mtomiyoshi for the report, Marten Kenbeek for the initial patch and Tim for the review.
This commit is contained in:
parent
3ab55c1a8a
commit
040bd7c938
3 changed files with 31 additions and 1 deletions
|
@ -5,7 +5,7 @@ import unittest
|
|||
from django.db import connection, migrations, models, transaction
|
||||
from django.db.migrations.migration import Migration
|
||||
from django.db.migrations.operations import CreateModel
|
||||
from django.db.migrations.state import ProjectState
|
||||
from django.db.migrations.state import ModelState, ProjectState
|
||||
from django.db.models.fields import NOT_PROVIDED
|
||||
from django.db.transaction import atomic
|
||||
from django.db.utils import IntegrityError
|
||||
|
@ -590,6 +590,26 @@ class OperationTests(OperationTestBase):
|
|||
self.assertEqual(definition[1], [])
|
||||
self.assertEqual(definition[2], {'old_name': "Pony", 'new_name': "Horse"})
|
||||
|
||||
def test_rename_model_state_forwards(self):
|
||||
"""
|
||||
RenameModel operations shouldn't trigger the caching of rendered apps
|
||||
on state without prior apps.
|
||||
"""
|
||||
state = ProjectState()
|
||||
state.add_model(ModelState('migrations', 'Foo', []))
|
||||
operation = migrations.RenameModel('Foo', 'Bar')
|
||||
operation.state_forwards('migrations', state)
|
||||
self.assertNotIn('apps', state.__dict__)
|
||||
self.assertNotIn(('migrations', 'foo'), state.models)
|
||||
self.assertIn(('migrations', 'bar'), state.models)
|
||||
# Now with apps cached.
|
||||
apps = state.apps
|
||||
operation = migrations.RenameModel('Bar', 'Foo')
|
||||
operation.state_forwards('migrations', state)
|
||||
self.assertIs(state.apps, apps)
|
||||
self.assertNotIn(('migrations', 'bar'), state.models)
|
||||
self.assertIn(('migrations', 'foo'), state.models)
|
||||
|
||||
def test_rename_model_with_self_referential_fk(self):
|
||||
"""
|
||||
Tests the RenameModel operation on model with self referential FK.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue