Skip to content

Commit dce5072

Browse files
authored
PYTHON-3137 Handle falsey values for "let" parameter (mongodb#881)
1 parent e6b6586 commit dce5072

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

pymongo/aggregation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(
5555
self._performs_write = True
5656

5757
common.validate_is_mapping("options", options)
58-
if let:
58+
if let is not None:
5959
common.validate_is_mapping("let", let)
6060
options["let"] = let
6161
if comment is not None:

pymongo/collection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ def _update(
728728
hint = helpers._index_document(hint)
729729
update_doc["hint"] = hint
730730
command = SON([("update", self.name), ("ordered", ordered), ("updates", [update_doc])])
731-
if let:
731+
if let is not None:
732732
common.validate_is_mapping("let", let)
733733
command["let"] = let
734734
if not write_concern.is_server_default:
@@ -893,7 +893,7 @@ def replace_one(
893893
"""
894894
common.validate_is_mapping("filter", filter)
895895
common.validate_ok_for_replace(replacement)
896-
if let:
896+
if let is not None:
897897
common.validate_is_mapping("let", let)
898898
write_concern = self._write_concern_for(session)
899899
return UpdateResult(
@@ -1189,7 +1189,7 @@ def _delete(
11891189
if not write_concern.is_server_default:
11901190
command["writeConcern"] = write_concern.document
11911191

1192-
if let:
1192+
if let is not None:
11931193
common.validate_is_document_type("let", let)
11941194
command["let"] = let
11951195

@@ -2728,7 +2728,7 @@ def __find_and_modify(
27282728
)
27292729
collation = validate_collation_or_none(kwargs.pop("collation", None))
27302730
cmd = SON([("findAndModify", self.__name), ("query", filter), ("new", return_document)])
2731-
if let:
2731+
if let is not None:
27322732
common.validate_is_mapping("let", let)
27332733
cmd["let"] = let
27342734
cmd.update(kwargs)

pymongo/cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def __init__(
248248
if projection is not None:
249249
projection = helpers._fields_list_to_dict(projection, "projection")
250250

251-
if let:
251+
if let is not None:
252252
validate_is_document_type("let", let)
253253

254254
self.__let = let

test/test_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2123,7 +2123,7 @@ def test_helpers_with_let(self):
21232123
(c.find_one_and_replace, ({}, {})),
21242124
(c.aggregate, ([], {})),
21252125
]
2126-
for let in [10, "str"]:
2126+
for let in [10, "str", [], False]:
21272127
for helper, args in helpers:
21282128
with self.assertRaisesRegex(TypeError, "let must be an instance of dict"):
21292129
helper(*args, let=let) # type: ignore

0 commit comments

Comments
 (0)