From c1621d80089cb3e77c8a504310feeb24fea61afe Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Fri, 30 Jun 2017 08:35:58 -0400 Subject: [1.11.x] Fixed #28350 -- Fixed UnboundLocalError crash in RenameField with nonexistent field. Thanks Tim for the review. Backport of 5cbcb3683964205ce023157ca181d05a31be2ab5 from master --- tests/migrations/test_operations.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests') diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index 3b2bd8275c..64ae395d94 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import unittest +from django.core.exceptions import FieldDoesNotExist from django.db import connection, migrations, models, transaction from django.db.migrations.migration import Migration from django.db.migrations.operations import CreateModel @@ -1370,6 +1371,12 @@ class OperationTests(OperationTestBase): self.assertEqual(definition[1], []) self.assertEqual(definition[2], {'model_name': "Pony", 'old_name': "pink", 'new_name': "blue"}) + def test_rename_missing_field(self): + state = ProjectState() + state.add_model(ModelState('app', 'model', [])) + with self.assertRaisesMessage(FieldDoesNotExist, "app.model has no field named 'field'"): + migrations.RenameField('model', 'field', 'new_field').state_forwards('app', state) + def test_alter_unique_together(self): """ Tests the AlterUniqueTogether operation. -- cgit v1.3