PYTHON-3137 Handle falsey values for "let" parameter (#881)

This commit is contained in:
Julius Park 2022-02-18 10:43:07 -08:00 committed by GitHub
parent e6b65860f5
commit dce5072dd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 7 deletions

View File

@ -55,7 +55,7 @@ class _AggregationCommand(object):
self._performs_write = True
common.validate_is_mapping("options", options)
if let:
if let is not None:
common.validate_is_mapping("let", let)
options["let"] = let
if comment is not None:

View File

@ -728,7 +728,7 @@ class Collection(common.BaseObject, Generic[_DocumentType]):
hint = helpers._index_document(hint)
update_doc["hint"] = hint
command = SON([("update", self.name), ("ordered", ordered), ("updates", [update_doc])])
if let:
if let is not None:
common.validate_is_mapping("let", let)
command["let"] = let
if not write_concern.is_server_default:
@ -893,7 +893,7 @@ class Collection(common.BaseObject, Generic[_DocumentType]):
"""
common.validate_is_mapping("filter", filter)
common.validate_ok_for_replace(replacement)
if let:
if let is not None:
common.validate_is_mapping("let", let)
write_concern = self._write_concern_for(session)
return UpdateResult(
@ -1189,7 +1189,7 @@ class Collection(common.BaseObject, Generic[_DocumentType]):
if not write_concern.is_server_default:
command["writeConcern"] = write_concern.document
if let:
if let is not None:
common.validate_is_document_type("let", let)
command["let"] = let
@ -2728,7 +2728,7 @@ class Collection(common.BaseObject, Generic[_DocumentType]):
)
collation = validate_collation_or_none(kwargs.pop("collation", None))
cmd = SON([("findAndModify", self.__name), ("query", filter), ("new", return_document)])
if let:
if let is not None:
common.validate_is_mapping("let", let)
cmd["let"] = let
cmd.update(kwargs)

View File

@ -248,7 +248,7 @@ class Cursor(Generic[_DocumentType]):
if projection is not None:
projection = helpers._fields_list_to_dict(projection, "projection")
if let:
if let is not None:
validate_is_document_type("let", let)
self.__let = let

View File

@ -2123,7 +2123,7 @@ class TestCollection(IntegrationTest):
(c.find_one_and_replace, ({}, {})),
(c.aggregate, ([], {})),
]
for let in [10, "str"]:
for let in [10, "str", [], False]:
for helper, args in helpers:
with self.assertRaisesRegex(TypeError, "let must be an instance of dict"):
helper(*args, let=let) # type: ignore