From 167b0b6f37c3a0de38ede6239b5c948262547fc7 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 13 Sep 2024 15:53:34 -0400 Subject: [PATCH] fix SchemaEditor.alter_db_table() crash when table name is unchanged --- django_mongodb/features.py | 4 ---- django_mongodb/schema.py | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/django_mongodb/features.py b/django_mongodb/features.py index e0f80b400..e5911c074 100644 --- a/django_mongodb/features.py +++ b/django_mongodb/features.py @@ -131,10 +131,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): "schema.tests.SchemaTests.test_composed_constraint_with_fk", "schema.tests.SchemaTests.test_remove_ignored_unique_constraint_not_create_fk_index", "schema.tests.SchemaTests.test_unique_constraint", - # pymongo.errors.OperationFailure: Can't rename a collection to itself - "migrations.test_operations.OperationTests.test_alter_model_table_noop", - "migrations.test_operations.OperationTests.test_rename_model_no_relations_with_db_table_noop", - "migrations.test_operations.OperationTests.test_rename_model_with_db_table_rename_m2m", # subclasses of BaseDatabaseIntrospection may require a get_constraints() method "migrations.test_operations.OperationTests.test_add_func_unique_constraint", "migrations.test_operations.OperationTests.test_remove_func_unique_constraint", diff --git a/django_mongodb/schema.py b/django_mongodb/schema.py index 5867a2365..d2f109c6d 100644 --- a/django_mongodb/schema.py +++ b/django_mongodb/schema.py @@ -75,4 +75,6 @@ def remove_constraint(self, model, constraint): pass def alter_db_table(self, model, old_db_table, new_db_table): + if old_db_table == new_db_table: + return self.connection.database[old_db_table].rename(new_db_table)