Skip to content

Commit c5bc46b

Browse files
WaVEVtimgraham
authored andcommitted
Remove contained_by and all lookups
1 parent c0a239e commit c5bc46b

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
@@ -104,8 +104,6 @@ class _EmbeddedModelArrayOutputField(ArrayField):
104104
"gte",
105105
"lt",
106106
"lte",
107-
"all",
108-
"contained_by",
109107
}
110108

111109
def get_lookup(self, name):
@@ -178,23 +176,6 @@ class EmbeddedModelArrayFieldLessThanOrEqual(
178176
pass
179177

180178

181-
@_EmbeddedModelArrayOutputField.register_lookup
182-
class EmbeddedModelArrayFieldAll(EmbeddedModelArrayFieldBuiltinLookup, Lookup):
183-
lookup_name = "all"
184-
get_db_prep_lookup_value_is_iterable = False
185-
186-
def as_mql(self, compiler, connection):
187-
lhs_mql = process_lhs(self, compiler, connection)
188-
values = process_rhs(self, compiler, connection)
189-
return {
190-
"$and": [
191-
{"$ne": [lhs_mql, None]},
192-
{"$ne": [values, None]},
193-
{"$setIsSubset": [values, lhs_mql]},
194-
]
195-
}
196-
197-
198179
class KeyTransform(Transform):
199180
def __init__(self, key_name, array_field, *args, **kwargs):
200181
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)