Skip to content

Commit c770364

Browse files
committed
update docs/tests for $facet removal
1 parent 0d0f650 commit c770364

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

docs/ref/models/encrypted-fields.rst

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,16 @@ may vary.
124124
- :meth:`~django.db.models.query.QuerySet.alias`,
125125
:meth:`~django.db.models.query.QuerySet.annotate`,
126126
:meth:`~django.db.models.query.QuerySet.distinct`: Cannot group on field
127-
'_id.value' which is encrypted with the random algorithm or whose encryption
128-
properties are not known until runtime.
127+
'<encrypted_field>' which is encrypted with the random algorithm or whose
128+
encryption properties are not known until runtime.
129129
- :meth:`~django.db.models.query.QuerySet.dates`,
130130
:meth:`~django.db.models.query.QuerySet.datetimes`: If the value type is a
131131
date, the type of the index must also be date (and vice versa).
132132
- :meth:`~django.db.models.query.QuerySet.in_bulk`: Encrypted fields can't have
133133
unique constraints.
134-
135-
# TODO: add details about joined queries after
136-
https://github.com/mongodb/django-mongodb-backend/pull/443 is finalized.
134+
- Queries that join multiple collections and require the ``let`` operator. Such
135+
queries usually involve expressions or subqueries: Non-empty 'let' field is
136+
not allowed in the $lookup aggregation stage over an encrypted collection.
137137

138138
There are also several ``QuerySet`` methods that aren't permitted on any models
139139
(regardless of whether or not they have encrypted fields) that use a database
@@ -142,10 +142,8 @@ sample error message from the database.
142142

143143
- :meth:`~django.db.models.query.QuerySet.update`: Multi-document updates are
144144
not allowed with Queryable Encryption.
145-
- :meth:`~django.db.models.query.QuerySet.aggregate`,
146-
:meth:`~django.db.models.query.QuerySet.count`: Aggregation stage
147-
$internalFacetTeeConsumer is not allowed or supported with automatic
148-
encryption.
145+
- :meth:`~django.db.models.query.QuerySet.aggregate`: Invalid reference to an
146+
encrypted field within aggregate expression.
149147
- :meth:`~django.db.models.query.QuerySet.union`: Aggregation stage $unionWith
150148
is not allowed or supported with automatic encryption.
151149

tests/encryption_/test_fields.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from bson import ObjectId
77
from django.db import DatabaseError
8-
from django.db.models import Avg, F, Q
8+
from django.db.models import Avg, Count, F, Q
99

1010
from django_mongodb_backend.fields import (
1111
EncryptedArrayField,
@@ -243,14 +243,18 @@ def test_time(self):
243243

244244

245245
class QueryTests(EncryptionTestCase):
246-
def test_aggregate(self):
246+
def test_aggregate_avg(self):
247247
msg = (
248-
"Aggregation stage $internalFacetTeeConsumer is not allowed or "
249-
"supported with automatic encryption."
248+
"csfle \"analyze_query\" failed: Accumulator '$avg' cannot aggregate encrypted fields."
250249
)
251250
with self.assertRaisesMessage(DatabaseError, msg):
252251
list(IntegerModel.objects.aggregate(Avg("value")))
253252

253+
def test_aggregate_count(self):
254+
msg = "Invalid reference to an encrypted field within aggregate expression: value"
255+
with self.assertRaisesMessage(DatabaseError, msg):
256+
list(IntegerModel.objects.aggregate(Count("value")))
257+
254258
def test_alias(self):
255259
msg = (
256260
"Cannot group on field '_id.value' which is encrypted with the "
@@ -291,12 +295,9 @@ def test_contains(self):
291295
self.assertIs(CharModel.objects.contains(obj), True)
292296

293297
def test_count(self):
294-
msg = (
295-
"Aggregation stage $internalFacetTeeConsumer is not allowed or "
296-
"supported with automatic encryption."
297-
)
298-
with self.assertRaisesMessage(DatabaseError, msg):
299-
list(CharModel.objects.count())
298+
CharModel.objects.create(value="a")
299+
CharModel.objects.create(value="b")
300+
self.assertEqual(CharModel.objects.count(), 2)
300301

301302
def test_dates(self):
302303
msg = (

0 commit comments

Comments
 (0)