From be0f9ba15a15e24a05a28e79390afdd742f06dcf Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Sat, 14 Dec 2024 15:21:24 -0500 Subject: [PATCH] update to Django 5.2 --- .github/workflows/test-python.yml | 2 +- django_mongodb/__init__.py | 2 +- django_mongodb/features.py | 20 ++++++++++++++++++++ django_mongodb/lookups.py | 7 ++++--- django_mongodb/operations.py | 22 ---------------------- django_mongodb/query_utils.py | 5 +---- 6 files changed, 27 insertions(+), 31 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 91e897a0..745b9163 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.1.x' + ref: 'mongodb-5.2.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 83087b54..5d351c5a 100644 --- a/django_mongodb/__init__.py +++ b/django_mongodb/__init__.py @@ -1,4 +1,4 @@ -__version__ = "5.1a0" +__version__ = "5.2a0" # Check Django compatibility before other imports which may fail if the # wrong version of Django is installed. diff --git a/django_mongodb/features.py b/django_mongodb/features.py index e388f525..cc88fd6d 100644 --- a/django_mongodb/features.py +++ b/django_mongodb/features.py @@ -89,6 +89,23 @@ class DatabaseFeatures(BaseDatabaseFeatures): "auth_tests.test_views.LoginTest.test_login_session_without_hash_session_key", # GenericRelation.value_to_string() assumes integer pk. "contenttypes_tests.test_fields.GenericRelationTests.test_value_to_string", + # Broken by https://github.com/django/django/commit/65ad4ade74dc9208b9d686a451cd6045df0c9c3a + "aggregation.tests.AggregateTestCase.test_even_more_aggregate", + "aggregation.tests.AggregateTestCase.test_grouped_annotation_in_group_by", + "aggregation.tests.AggregateTestCase.test_non_grouped_annotation_not_in_group_by", + "aggregation_regress.tests.AggregationTests.test_aggregate_fexpr", + "aggregation_regress.tests.AggregationTests.test_values_list_annotation_args_ordering", + "annotations.tests.NonAggregateAnnotationTestCase.test_annotation_subquery_and_aggregate_values_chaining", + "annotations.tests.NonAggregateAnnotationTestCase.test_values_fields_annotations_order", + "queries.test_qs_combinators.QuerySetSetOperationTests.test_union_multiple_models_with_values_and_datetime_annotations", + "queries.test_qs_combinators.QuerySetSetOperationTests.test_union_multiple_models_with_values_list_and_datetime_annotations", + "queries.test_qs_combinators.QuerySetSetOperationTests.test_union_multiple_models_with_values_list_and_annotations", + "queries.test_qs_combinators.QuerySetSetOperationTests.test_union_with_field_and_annotation_values", + "queries.test_qs_combinators.QuerySetSetOperationTests.test_union_with_two_annotated_values_list", + "queries.tests.Queries1Tests.test_union_values_subquery", + # pymongo.errors.WriteError: Performing an update on the path '_id' + # would modify the immutable field '_id' + "migrations.test_operations.OperationTests.test_composite_pk_operations", } # $bitAnd, #bitOr, and $bitXor are new in MongoDB 6.3. _django_test_expected_failures_bitwise = { @@ -600,6 +617,9 @@ def django_test_expected_failures(self): "foreign_object.tests.MultiColumnFKTests", "foreign_object.tests.TestExtraJoinFilterQ", }, + "Tuple lookups are not supported.": { + "foreign_object.test_tuple_lookups.TupleLookupsTests", + }, "Custom lookups are not supported.": { "custom_lookups.tests.BilateralTransformTests", "custom_lookups.tests.LookupTests.test_basic_lookup", diff --git a/django_mongodb/lookups.py b/django_mongodb/lookups.py index c651dd6a..2118c4ed 100644 --- a/django_mongodb/lookups.py +++ b/django_mongodb/lookups.py @@ -1,5 +1,6 @@ from django.db import NotSupportedError -from django.db.models.fields.related_lookups import In, MultiColSource, RelatedIn +from django.db.models.expressions import ColPairs +from django.db.models.fields.related_lookups import In, RelatedIn from django.db.models.lookups import ( BuiltinLookup, FieldGetDbPrepValueIterableMixin, @@ -34,8 +35,8 @@ def field_resolve_expression_parameter(self, compiler, connection, sql, param): def in_(self, compiler, connection): - if isinstance(self.lhs, MultiColSource): - raise NotImplementedError("MultiColSource is not supported.") + if isinstance(self.lhs, ColPairs): + raise NotImplementedError("ColPairs is not supported.") db_rhs = getattr(self.rhs, "_db", None) if db_rhs is not None and db_rhs != connection.alias: raise ValueError( diff --git a/django_mongodb/operations.py b/django_mongodb/operations.py index a6363bed..6385baf1 100644 --- a/django_mongodb/operations.py +++ b/django_mongodb/operations.py @@ -179,28 +179,6 @@ def execute_sql_flush(self, tables): if not options.get("capped", False): collection.delete_many({}) - def prep_lookup_value(self, value, field, lookup): - """ - Perform type-conversion on `value` before using as a filter parameter. - """ - if getattr(field, "rel", None) is not None: - field = field.rel.get_related_field() - field_kind = field.get_internal_type() - - if lookup in ("in", "range"): - return [ - self._prep_lookup_value(subvalue, field, field_kind, lookup) for subvalue in value - ] - return self._prep_lookup_value(value, field, field_kind, lookup) - - def _prep_lookup_value(self, value, field, field_kind, lookup): - if value is None: - return None - - if field_kind == "DecimalField": - value = self.adapt_decimalfield_value(value, field.max_digits, field.decimal_places) - return value - def explain_query_prefix(self, format=None, **options): # Validate options. validated_options = {} diff --git a/django_mongodb/query_utils.py b/django_mongodb/query_utils.py index 892cd77b..d007980e 100644 --- a/django_mongodb/query_utils.py +++ b/django_mongodb/query_utils.py @@ -42,10 +42,7 @@ def process_rhs(node, compiler, connection): value = value[0] if hasattr(node, "prep_lookup_value_mongo"): value = node.prep_lookup_value_mongo(value) - # No need to prepare expressions like F() objects. - if hasattr(rhs, "resolve_expression"): - return value - return connection.ops.prep_lookup_value(value, node.lhs.output_field, node.lookup_name) + return value def regex_match(field, regex_vals, insensitive=False):