diff --git a/mongoengine/fields.py b/mongoengine/fields.py index f50e6045..8fdeae15 100644 --- a/mongoengine/fields.py +++ b/mongoengine/fields.py @@ -774,7 +774,7 @@ class EmbeddedDocumentField(BaseField): def prepare_query_value(self, op, value): if value is not None and not isinstance(value, self.document_type): # Short circuit for special operators, returning them as is - if isinstance(value, dict) and all(k.startswith('$') for k in value.keys()): + if isinstance(value, dict) and all(k.startswith("$") for k in value.keys()): return value try: value = self.document_type._from_son(value) diff --git a/tests/queryset/test_transform.py b/tests/queryset/test_transform.py index 0fba3975..f5d248af 100644 --- a/tests/queryset/test_transform.py +++ b/tests/queryset/test_transform.py @@ -352,24 +352,19 @@ class TestTransform(unittest.TestCase): class Drink(EmbeddedDocument): id = StringField() - meta = { - 'strict': False - } + meta = {"strict": False} class Shop(Document): drinks = EmbeddedDocumentListField(Drink) Shop.drop_collection() - drinks = [Drink(id='drink_1'), Drink(id='drink_2')] + drinks = [Drink(id="drink_1"), Drink(id="drink_2")] Shop.objects.create(drinks=drinks) q_obj = transform.query( - Shop, - drinks__all=[{'$elemMatch': {'_id': x.id}} for x in drinks] + Shop, drinks__all=[{"$elemMatch": {"_id": x.id}} for x in drinks] ) assert q_obj == { - 'drinks': { - '$all': [{'$elemMatch': {'_id': x.id}} for x in drinks] - } + "drinks": {"$all": [{"$elemMatch": {"_id": x.id}} for x in drinks]} } Shop.drop_collection()