mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[1.10.x] 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.
Backport of 040bd7c938 from master
			
			
This commit is contained in:
		| @@ -4,7 +4,7 @@ import unittest | ||||
|  | ||||
| from django.db import connection, migrations, models, transaction | ||||
| from django.db.migrations.migration import Migration | ||||
| 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 | ||||
| @@ -579,6 +579,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. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user