Skip to content

Commit 5ec57e6

Browse files
WaVEVtimgraham
authored andcommitted
Remove contained_by and all lookups
1 parent 693736f commit 5ec57e6

File tree

3 files changed

+2
-85
lines changed

3 files changed

+2
-85
lines changed

django_mongodb_backend/fields/embedded_model_array.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ class _EmbeddedModelArrayOutputField(ArrayField):
9292
"gte",
9393
"lt",
9494
"lte",
95-
"all",
96-
"contained_by",
9795
}
9896

9997
def get_lookup(self, name):
@@ -166,23 +164,6 @@ class EmbeddedModelArrayFieldLessThanOrEqual(
166164
pass
167165

168166

169-
@_EmbeddedModelArrayOutputField.register_lookup
170-
class EmbeddedModelArrayFieldAll(EmbeddedModelArrayFieldBuiltinLookup, Lookup):
171-
lookup_name = "all"
172-
get_db_prep_lookup_value_is_iterable = False
173-
174-
def as_mql(self, compiler, connection):
175-
lhs_mql = process_lhs(self, compiler, connection)
176-
values = process_rhs(self, compiler, connection)
177-
return {
178-
"$and": [
179-
{"$ne": [lhs_mql, None]},
180-
{"$ne": [values, None]},
181-
{"$setIsSubset": [values, lhs_mql]},
182-
]
183-
}
184-
185-
186167
class KeyTransform(Transform):
187168
def __init__(self, key_name, array_field, *args, **kwargs):
188169
super().__init__(*args, **kwargs)

docs/source/ref/models/fields.rst

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -448,58 +448,6 @@ Examples:
448448
Post.objects.filter(tags__rating__lte=3)
449449
<QuerySet [<Post: First post>, <Post: Second post>]>
450450
451-
.. fieldlookup:: embeddedmodelarrayfield.all
452-
453-
``all``
454-
^^^^^^^
455-
456-
Returns objects where **all** values provided on the right-hand side are
457-
present. It requires that *every* value be matched by some document in
458-
the array.
459-
460-
Example:
461-
462-
.. code-block:: pycon
463-
464-
Post.objects.create(
465-
name="First post", tags=[Tag(label="django"), Tag(label="rest")]
466-
)
467-
Post.objects.create(
468-
name="Second post", tags=[Tag(label="django")]
469-
)
470-
471-
Post.objects.filter(tags__label__all=["django", "rest"])
472-
<QuerySet [<Post: First post>]>
473-
474-
Post.objects.filter(tags__label__all=["django"])
475-
<QuerySet [<Post: First post>, <Post: Second post>]>
476-
477-
.. fieldlookup:: embeddedmodelarrayfield.contained_by
478-
479-
``contained_by``
480-
^^^^^^^^^^^^^^^^
481-
482-
Returns objects where the embedded model array is **contained by** the list of
483-
values on the right-hand side. In other words, every value in the embedded
484-
array must be present in the given list.
485-
486-
Example:
487-
488-
.. code-block:: pycon
489-
490-
Post.objects.create(
491-
name="First post", tags=[Tag(label="django"), Tag(label="rest")]
492-
)
493-
Post.objects.create(
494-
name="Second post", tags=[Tag(label="django")]
495-
)
496-
497-
Post.objects.filter(tags__label__contained_by=["django", "rest", "api"])
498-
<QuerySet [<Post: First post>, <Post: Second post>]>
499-
500-
Post.objects.filter(tags__label__contained_by=["django"])
501-
<QuerySet [<Post: Second post>]>
502-
503451
``ObjectIdAutoField``
504452
---------------------
505453

tests/model_fields_/test_embedded_model_array.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,6 @@ def test_filter_unsupported_lookups(self):
182182
self.assertCountEqual(MuseumExhibit.objects.filter(**kwargs), [])
183183
self.assertIn(f"'field': '{lookup}'", captured_queries[0]["sql"])
184184

185-
def test_all_filter(self):
186-
self.assertCountEqual(
187-
MuseumExhibit.objects.filter(sections__section_number__all=[1, 2]), [self.wonders]
188-
)
189-
190-
def test_contained_by(self):
191-
self.assertCountEqual(
192-
MuseumExhibit.objects.filter(sections__section_number__contained_by=[1, 2, 3]),
193-
[self.egypt, self.new_descoveries, self.wonders, self.lost_empires],
194-
)
195-
196185
def test_len_filter(self):
197186
self.assertCountEqual(MuseumExhibit.objects.filter(sections__len=10), [])
198187
self.assertCountEqual(
@@ -305,9 +294,8 @@ def test_foreign_field_exact(self):
305294
self.assertCountEqual(qs, [self.egypt_tour, self.wonders_tour])
306295

307296
def test_foreign_field_with_slice(self):
308-
# Only wonders exhibit has exactly two sections, and this slice matches first two
309-
qs = Tour.objects.filter(exhibit__sections__0_2__section_number__all=[1, 2])
310-
self.assertEqual(list(qs), [self.wonders_tour])
297+
qs = Tour.objects.filter(exhibit__sections__0_2__section_number__in=[1, 2])
298+
self.assertCountEqual(qs, [self.wonders_tour, self.egypt_tour])
311299

312300

313301
@isolate_apps("model_fields_")

0 commit comments

Comments
 (0)