From f212568dce3e201ea19cc26a392b1f06e8f3279c Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 8 Jul 2024 11:01:58 -0400 Subject: [PATCH] update to Django 5.1 --- .github/workflows/test-python.yml | 2 +- django_mongodb/__init__.py | 2 +- django_mongodb/compiler.py | 2 +- django_mongodb/features.py | 13 +++++++++++++ django_mongodb/query_utils.py | 2 ++ django_mongodb/schema.py | 7 ++----- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 16bfb2e1..91e897a0 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -33,7 +33,7 @@ jobs: uses: actions/checkout@v4 with: repository: 'mongodb-forks/django' - ref: 'mongodb-5.0.x' + ref: 'mongodb-5.1.x' path: 'django_repo' persist-credentials: false - name: Install system packages for Django's Python test dependencies diff --git a/django_mongodb/__init__.py b/django_mongodb/__init__.py index 5ee8bc1c..83087b54 100644 --- a/django_mongodb/__init__.py +++ b/django_mongodb/__init__.py @@ -1,4 +1,4 @@ -__version__ = "5.0a0" +__version__ = "5.1a0" # Check Django compatibility before other imports which may fail if the # wrong version of Django is installed. diff --git a/django_mongodb/compiler.py b/django_mongodb/compiler.py index 46d3afaa..a0508cf5 100644 --- a/django_mongodb/compiler.py +++ b/django_mongodb/compiler.py @@ -91,7 +91,7 @@ def _prepare_expressions_for_pipeline(self, expression, target, annotation_group rhs = sub_expr.as_mql(self, self.connection, resolve_inner_expression=True) group[alias] = {"$addToSet": rhs} replacing_expr = sub_expr.copy() - replacing_expr.set_source_expressions([inner_column]) + replacing_expr.set_source_expressions([inner_column, None]) else: group[alias] = sub_expr.as_mql(self, self.connection) replacing_expr = inner_column diff --git a/django_mongodb/features.py b/django_mongodb/features.py index 4e585242..e388f525 100644 --- a/django_mongodb/features.py +++ b/django_mongodb/features.py @@ -46,6 +46,12 @@ class DatabaseFeatures(BaseDatabaseFeatures): uses_savepoints = False _django_test_expected_failures = { + # $concat only supports strings, not int + "db_functions.text.test_concat.ConcatTests.test_concat_non_str", + # QuerySet.order_by() with annotation transform doesn't work: + # "Expression $mod takes exactly 2 arguments. 1 were passed in" + # https://github.com/django/django/commit/b0ad41198b3e333f57351e3fce5a1fb47f23f376 + "aggregation.tests.AggregateTestCase.test_order_by_aggregate_transform", # 'NulledTransform' object has no attribute 'as_mql'. "lookup.tests.LookupTests.test_exact_none_transform", # "Save with update_fields did not affect any rows." @@ -78,6 +84,7 @@ class DatabaseFeatures(BaseDatabaseFeatures): # Connection creation doesn't follow the usual Django API. "backends.tests.ThreadTests.test_pass_connection_between_threads", "backends.tests.ThreadTests.test_default_connection_thread_local", + "test_utils.tests.DisallowedDatabaseQueriesTests.test_disallowed_thread_database_connection", # Object of type ObjectId is not JSON serializable. "auth_tests.test_views.LoginTest.test_login_session_without_hash_session_key", # GenericRelation.value_to_string() assumes integer pk. @@ -170,6 +177,7 @@ def django_test_expected_failures(self): "fixtures.tests.FixtureLoadingTests.test_loading_and_dumping", "m2m_through_regress.test_multitable.MultiTableTests.test_m2m_prefetch_proxied", "m2m_through_regress.test_multitable.MultiTableTests.test_m2m_prefetch_reverse_proxied", + "many_to_many.tests.ManyToManyQueryTests.test_prefetch_related_no_queries_optimization_disabled", "many_to_many.tests.ManyToManyTests.test_add_after_prefetch", "many_to_many.tests.ManyToManyTests.test_add_then_remove_after_prefetch", "many_to_many.tests.ManyToManyTests.test_clear_after_prefetch", @@ -381,7 +389,11 @@ def django_test_expected_failures(self): "delete.tests.DeletionTests.test_only_referenced_fields_selected", "expressions.tests.ExistsTests.test_optimizations", "lookup.tests.LookupTests.test_in_ignore_none", + "lookup.tests.LookupTests.test_lookup_direct_value_rhs_unwrapped", "lookup.tests.LookupTests.test_textfield_exact_null", + "many_to_many.tests.ManyToManyQueryTests.test_count_join_optimization_disabled", + "many_to_many.tests.ManyToManyQueryTests.test_exists_join_optimization_disabled", + "many_to_many.tests.ManyToManyTests.test_custom_default_manager_exists_count", "migrations.test_commands.MigrateTests.test_migrate_syncdb_app_label", "migrations.test_commands.MigrateTests.test_migrate_syncdb_deferred_sql_executed_with_schemaeditor", "queries.tests.ExistsSql.test_exists", @@ -429,6 +441,7 @@ def django_test_expected_failures(self): "raw_query.tests.RawQueryTests", "schema.test_logging.SchemaLoggerTests.test_extra_args", "schema.tests.SchemaTests.test_remove_constraints_capital_letters", + "test_utils.tests.AllowedDatabaseQueriesTests.test_allowed_database_copy_queries", "timezones.tests.LegacyDatabaseTests.test_cursor_execute_accepts_naive_datetime", "timezones.tests.LegacyDatabaseTests.test_cursor_execute_returns_naive_datetime", "timezones.tests.LegacyDatabaseTests.test_raw_sql", diff --git a/django_mongodb/query_utils.py b/django_mongodb/query_utils.py index ff98a1ed..892cd77b 100644 --- a/django_mongodb/query_utils.py +++ b/django_mongodb/query_utils.py @@ -12,6 +12,8 @@ def process_lhs(node, compiler, connection): # node is a Func or Expression, possibly with multiple source expressions. result = [] for expr in node.get_source_expressions(): + if expr is None: + continue try: result.append(expr.as_mql(compiler, connection)) except FullResultSet: diff --git a/django_mongodb/schema.py b/django_mongodb/schema.py index 8fc18fea..45db1c4b 100644 --- a/django_mongodb/schema.py +++ b/django_mongodb/schema.py @@ -31,8 +31,8 @@ def create_model(self, model): def _create_model_indexes(self, model): """ - Create all indexes (field indexes & uniques, Meta.index_together, - Meta.unique_together, Meta.constraints, Meta.indexes) for the model. + Create all indexes (field indexes & uniques, Meta.unique_together, + Meta.constraints, Meta.indexes) for the model. """ if not model._meta.managed or model._meta.proxy or model._meta.swapped: return @@ -42,9 +42,6 @@ def _create_model_indexes(self, model): self._add_field_index(model, field) elif self._field_should_have_unique(field): self._add_field_unique(model, field) - # Meta.index_together (RemovedInDjango51Warning) - for field_names in model._meta.index_together: - self._add_composed_index(model, field_names) # Meta.unique_together if model._meta.unique_together: self.alter_unique_together(model, [], model._meta.unique_together)