1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #28350 -- Fixed UnboundLocalError crash in RenameField with nonexistent field.

Thanks Tim for the review.
This commit is contained in:
Simon Charette
2017-06-30 08:35:58 -04:00
parent b9f7dce84b
commit 5cbcb36839
3 changed files with 24 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
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
@@ -1368,6 +1369,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.