Skip to content

Commit

Permalink
fix test_contains_subquery
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Jan 8, 2025
1 parent 08ae4b4 commit aff20ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 0 additions & 3 deletions django_mongodb_backend/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ 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",
# contains with Exists() doesn't work:
# https://github.com/mongodb-labs/django-mongodb/issues/204
"model_fields_.test_arrayfield.QueryingTests.test_contains_subquery",
# overlap with values() returns no results:
# https://github.com/mongodb-labs/django-mongodb/issues/209
"model_fields_.test_arrayfield.QueryingTests.test_overlap_values",
Expand Down
8 changes: 7 additions & 1 deletion django_mongodb_backend/fields/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,13 @@ class ArrayContains(ArrayRHSMixin, FieldGetDbPrepValueMixin, Lookup):
def as_mql(self, compiler, connection):
lhs_mql = process_lhs(self, compiler, connection)
value = process_rhs(self, compiler, connection)
return {"$and": [{"$ne": [lhs_mql, None]}, {"$setIsSubset": [value, lhs_mql]}]}
return {
"$and": [
{"$ne": [lhs_mql, None]},
{"$ne": [value, None]},
{"$setIsSubset": [value, lhs_mql]},
]
}


@ArrayField.register_lookup
Expand Down

0 comments on commit aff20ae

Please sign in to comment.