From 215ae30ae08c134e19259e4cfe7085f0bcc8d72d Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 25 Sep 2024 14:58:41 -0400 Subject: [PATCH 1/2] add remaining migrations tests to CI --- .github/workflows/test-python.yml | 2 +- README.md | 3 +++ django_mongodb/features.py | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index a870b0e8d..dd449bb13 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -100,7 +100,7 @@ jobs: many_to_many many_to_one many_to_one_null - migrations.test_operations + migrations model_fields model_forms mutually_referential diff --git a/README.md b/README.md index c9f796ee1..7bd3fafa5 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,9 @@ from the new application's `apps.py` file. - You can study the skipped tests in `DatabaseFeatures.django_test_skips` for more details on known issues. +- Due to the lack of ability to introspect MongoDB collection schema, + `migrate --fake-initial` isn't supported. + ## Troubleshooting TODO diff --git a/django_mongodb/features.py b/django_mongodb/features.py index 4667b2637..254f3a779 100644 --- a/django_mongodb/features.py +++ b/django_mongodb/features.py @@ -533,6 +533,8 @@ def django_test_expected_failures(self): "expressions.tests.BasicExpressionsTests.test_annotate_values_filter", "expressions.tests.BasicExpressionsTests.test_filtering_on_rawsql_that_is_boolean", "expressions.tests.BasicExpressionsTests.test_order_by_multiline_sql", + "migrations.test_commands.MigrateTests.test_migrate_plan", + "migrations.test_multidb.MultiDBOperationTests.test_run_sql_migrate_foo_router_with_hints", "migrations.test_operations.OperationTests.test_run_sql", "migrations.test_operations.OperationTests.test_run_sql_params", "migrations.test_operations.OperationTests.test_separate_database_and_state", @@ -667,8 +669,29 @@ def django_test_expected_failures(self): }, "transaction.atomic() is not supported.": { "backends.base.test_base.DatabaseWrapperLoggingTests", + "migrations.test_executor.ExecutorTests.test_atomic_operation_in_non_atomic_migration", "migrations.test_operations.OperationTests.test_run_python_atomic", }, + "migrate --fake-initial is not supported.": { + "migrations.test_commands.MigrateTests.test_migrate_fake_initial", + "migrations.test_commands.MigrateTests.test_migrate_fake_split_initial", + "migrations.test_executor.ExecutorTests.test_soft_apply", + }, + "SchemaEditor doesn't log or collect queries.": { + # https://github.com/mongodb-labs/django-mongodb/issues/141 + "migrations.test_commands.MigrateTests.test_migrate_syncdb_app_label", + "migrations.test_commands.MigrateTests.test_migrate_syncdb_deferred_sql_executed_with_schemaeditor", + "migrations.test_commands.MigrateTests.test_sqlmigrate_backwards", + "migrations.test_commands.MigrateTests.test_sqlmigrate_for_non_atomic_migration", + "migrations.test_commands.MigrateTests.test_sqlmigrate_for_non_transactional_databases", + "migrations.test_commands.MigrateTests.test_sqlmigrate_forwards", + "migrations.test_commands.MigrateTests.test_sqlmigrate_replaced_migration", + "migrations.test_commands.MigrateTests.test_sqlmigrate_squashed_migration", + }, + "SchemaEditor.create_model() must raise DatabaseError rather than " + "pymongo.errors.CollectionInvalid: collection already exists": { + "migrations.test_commands.MigrateTests.test_migrate_initial_false", + }, } @cached_property From 8e53ed0a78cd7d9402d49c16cfc50b8b5aa93be6 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 25 Sep 2024 15:02:37 -0400 Subject: [PATCH 2/2] make SchemaEditor.create_model() raise DatabaseError if collection exists --- django_mongodb/features.py | 4 ---- django_mongodb/schema.py | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/django_mongodb/features.py b/django_mongodb/features.py index 254f3a779..c001de119 100644 --- a/django_mongodb/features.py +++ b/django_mongodb/features.py @@ -688,10 +688,6 @@ def django_test_expected_failures(self): "migrations.test_commands.MigrateTests.test_sqlmigrate_replaced_migration", "migrations.test_commands.MigrateTests.test_sqlmigrate_squashed_migration", }, - "SchemaEditor.create_model() must raise DatabaseError rather than " - "pymongo.errors.CollectionInvalid: collection already exists": { - "migrations.test_commands.MigrateTests.test_migrate_initial_false", - }, } @cached_property diff --git a/django_mongodb/schema.py b/django_mongodb/schema.py index 4e0f3581b..82592820c 100644 --- a/django_mongodb/schema.py +++ b/django_mongodb/schema.py @@ -1,7 +1,10 @@ from django.db.backends.base.schema import BaseDatabaseSchemaEditor +from .query import wrap_database_errors + class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): + @wrap_database_errors def create_model(self, model): self.connection.database.create_collection(model._meta.db_table) # Make implicit M2M tables.