Skip to content

Commit a81bc51

Browse files
committed
pre commit
1 parent e42f36d commit a81bc51

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

mongoengine/queryset/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,8 @@ def update(
567567
for u in update["__raw__"]
568568
]
569569
else:
570-
if 'array_filters' in update:
571-
array_filters = update.pop('array_filters')
570+
if "array_filters" in update:
571+
array_filters = update.pop("array_filters")
572572
update = transform.update(queryset._document, **update)
573573
# If doing an atomic upsert on an inheritable class
574574
# then ensure we add _cls to the update operation
@@ -584,7 +584,9 @@ def update(
584584
update_func = collection.update_one
585585
if multi:
586586
update_func = collection.update_many
587-
result = update_func(query, update, upsert=upsert, array_filters=array_filters)
587+
result = update_func(
588+
query, update, upsert=upsert, array_filters=array_filters
589+
)
588590
if full_result:
589591
return result
590592
elif result.raw_result:

tests/queryset/test_queryset.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,7 @@ class Blog(Document):
592592
Blog.drop_collection()
593593

594594
def test_update_array_filters(self):
595-
"""Ensure that updating by array_filters works.
596-
"""
595+
"""Ensure that updating by array_filters works."""
597596

598597
class Comment(EmbeddedDocument):
599598
comment_tags = ListField(StringField())
@@ -605,48 +604,48 @@ class Blog(Document):
605604
Blog.drop_collection()
606605

607606
# update one
608-
Blog.objects.create(tags=['test1', 'test2', 'test3'])
607+
Blog.objects.create(tags=["test1", "test2", "test3"])
609608

610-
Blog.objects().update_one(__raw__=
611-
{'$set': {"tags.$[element]": 'test11111'}},
612-
array_filters=[{"element": {'$eq': 'test2'}}],
613-
)
609+
Blog.objects().update_one(
610+
__raw__={"$set": {"tags.$[element]": "test11111"}},
611+
array_filters=[{"element": {"$eq": "test2"}}],
612+
)
614613
testc_blogs = Blog.objects(tags="test11111")
615614

616615
assert testc_blogs.count() == 1
617616

618617
Blog.drop_collection()
619618

620619
# update one inner list
621-
comments = Comment(comment_tags=['test1', 'test2', 'test3'])
620+
comments = Comment(comment_tags=["test1", "test2", "test3"])
622621
Blog.objects.create(comments=comments)
623622

624-
Blog.objects().update_one(__raw__=
625-
{'$set': {"comments.comment_tags.$[element]": 'test11111'}},
626-
array_filters=[{"element": {'$eq': 'test2'}}],
627-
)
623+
Blog.objects().update_one(
624+
__raw__={"$set": {"comments.comment_tags.$[element]": "test11111"}},
625+
array_filters=[{"element": {"$eq": "test2"}}],
626+
)
628627
testc_blogs = Blog.objects(comments__comment_tags="test11111")
629628

630629
assert testc_blogs.count() == 1
631630

632631
# update many
633632
Blog.drop_collection()
634633

635-
Blog.objects.create(tags=['test1', 'test2', 'test3', 'test_all'])
636-
Blog.objects.create(tags=['test4', 'test5', 'test6', 'test_all'])
634+
Blog.objects.create(tags=["test1", "test2", "test3", "test_all"])
635+
Blog.objects.create(tags=["test4", "test5", "test6", "test_all"])
637636

638-
Blog.objects().update(__raw__=
639-
{'$set': {"tags.$[element]": 'test11111'}},
640-
array_filters=[{"element": {'$eq': 'test2'}}],
641-
)
637+
Blog.objects().update(
638+
__raw__={"$set": {"tags.$[element]": "test11111"}},
639+
array_filters=[{"element": {"$eq": "test2"}}],
640+
)
642641
testc_blogs = Blog.objects(tags="test11111")
643642

644643
assert testc_blogs.count() == 1
645644

646-
Blog.objects().update(__raw__=
647-
{'$set': {"tags.$[element]": 'test_all1234577'}},
648-
array_filters=[{"element": {'$eq': 'test_all'}}],
649-
)
645+
Blog.objects().update(
646+
__raw__={"$set": {"tags.$[element]": "test_all1234577"}},
647+
array_filters=[{"element": {"$eq": "test_all"}}],
648+
)
650649
testc_blogs = Blog.objects(tags="test_all1234577")
651650

652651
assert testc_blogs.count() == 2

0 commit comments

Comments
 (0)