summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorÇağıl Uluşahin <cagilulusahin@gmail.com>2020-10-04 13:24:20 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-10-15 20:11:07 +0200
commit9159d173c3822312c653db7ff5b9a94b14af1dca (patch)
tree2f6f558601b875bc126c7d85db67f0598f1e3a5a /tests
parent68e33b347d5684214783ac65c5b4f0598f35c0f6 (diff)
Fixed #25253 -- Made AlterField operation a noop when changing attributes that don't affect the schema.
Diffstat (limited to 'tests')
-rw-r--r--tests/schema/tests.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 49fda069d3..e41db7a500 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -2758,6 +2758,35 @@ class SchemaTests(TransactionTestCase):
with connection.schema_editor() as editor, self.assertNumQueries(0):
editor.alter_field(AuthorWithDefaultHeight, old_field, new_field, strict=True)
+ @skipUnlessDBFeature('supports_foreign_keys')
+ def test_alter_field_fk_attributes_noop(self):
+ """
+ No queries are performed when changing field attributes that don't
+ affect the schema.
+ """
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.create_model(Book)
+ old_field = Book._meta.get_field('author')
+ new_field = ForeignKey(
+ Author,
+ blank=True,
+ editable=False,
+ error_messages={'invalid': 'error message'},
+ help_text='help text',
+ limit_choices_to={'limit': 'choice'},
+ on_delete=PROTECT,
+ related_name='related_name',
+ related_query_name='related_query_name',
+ validators=[lambda x: x],
+ verbose_name='verbose name',
+ )
+ new_field.set_attributes_from_name('author')
+ with connection.schema_editor() as editor, self.assertNumQueries(0):
+ editor.alter_field(Book, old_field, new_field, strict=True)
+ with connection.schema_editor() as editor, self.assertNumQueries(0):
+ editor.alter_field(Book, new_field, old_field, strict=True)
+
def test_add_textfield_unhashable_default(self):
# Create the table
with connection.schema_editor() as editor: