-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-4933 - Allow drivers to set bypassDocumentValidation: false on… #2227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -701,7 +701,7 @@ async def bulk_write( | |
self, | ||
requests: Sequence[_WriteOp[_DocumentType]], | ||
ordered: bool = True, | ||
bypass_document_validation: bool = False, | ||
bypass_document_validation: Optional[bool] = None, | ||
session: Optional[AsyncClientSession] = None, | ||
comment: Optional[Any] = None, | ||
let: Optional[Mapping] = None, | ||
|
@@ -800,8 +800,8 @@ async def _insert_one( | |
ordered: bool, | ||
write_concern: WriteConcern, | ||
op_id: Optional[int], | ||
bypass_doc_val: bool, | ||
session: Optional[AsyncClientSession], | ||
bypass_doc_val: Optional[bool] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our current internal APIs expect it to be a keyword argument and not positional. Is changing it to a positional argument intentional here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously it was positional: write_concern: WriteConcern,
op_id: Optional[int],
bypass_doc_val: bool,
session: Optional[AsyncClientSession], There's no need to change it to have a default of None because we always pass a value anyway so the default will never be used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just keep this one as positional and leave the rest. |
||
comment: Optional[Any] = None, | ||
) -> Any: | ||
"""Internal helper for inserting a single document.""" | ||
|
@@ -814,8 +814,8 @@ async def _insert_one( | |
async def _insert_command( | ||
session: Optional[AsyncClientSession], conn: AsyncConnection, retryable_write: bool | ||
) -> None: | ||
if bypass_doc_val: | ||
command["bypassDocumentValidation"] = True | ||
if bypass_doc_val is not None: | ||
command["bypassDocumentValidation"] = bypass_doc_val | ||
|
||
result = await conn.command( | ||
self._database.name, | ||
|
@@ -840,7 +840,7 @@ async def _insert_command( | |
async def insert_one( | ||
self, | ||
document: Union[_DocumentType, RawBSONDocument], | ||
bypass_document_validation: bool = False, | ||
bypass_document_validation: Optional[bool] = None, | ||
session: Optional[AsyncClientSession] = None, | ||
comment: Optional[Any] = None, | ||
) -> InsertOneResult: | ||
|
@@ -906,7 +906,7 @@ async def insert_many( | |
self, | ||
documents: Iterable[Union[_DocumentType, RawBSONDocument]], | ||
ordered: bool = True, | ||
bypass_document_validation: bool = False, | ||
bypass_document_validation: Optional[bool] = None, | ||
session: Optional[AsyncClientSession] = None, | ||
comment: Optional[Any] = None, | ||
) -> InsertManyResult: | ||
|
@@ -986,7 +986,7 @@ async def _update( | |
write_concern: Optional[WriteConcern] = None, | ||
op_id: Optional[int] = None, | ||
ordered: bool = True, | ||
bypass_doc_val: Optional[bool] = False, | ||
bypass_doc_val: Optional[bool] = None, | ||
collation: Optional[_CollationIn] = None, | ||
array_filters: Optional[Sequence[Mapping[str, Any]]] = None, | ||
hint: Optional[_IndexKeyHint] = None, | ||
|
@@ -1041,8 +1041,8 @@ async def _update( | |
if comment is not None: | ||
command["comment"] = comment | ||
# Update command. | ||
if bypass_doc_val: | ||
command["bypassDocumentValidation"] = True | ||
if bypass_doc_val is not None: | ||
command["bypassDocumentValidation"] = bypass_doc_val | ||
|
||
# The command result has to be published for APM unmodified | ||
# so we make a shallow copy here before adding updatedExisting. | ||
|
@@ -1082,7 +1082,7 @@ async def _update_retryable( | |
write_concern: Optional[WriteConcern] = None, | ||
op_id: Optional[int] = None, | ||
ordered: bool = True, | ||
bypass_doc_val: Optional[bool] = False, | ||
bypass_doc_val: Optional[bool] = None, | ||
collation: Optional[_CollationIn] = None, | ||
array_filters: Optional[Sequence[Mapping[str, Any]]] = None, | ||
hint: Optional[_IndexKeyHint] = None, | ||
|
@@ -1128,7 +1128,7 @@ async def replace_one( | |
filter: Mapping[str, Any], | ||
replacement: Mapping[str, Any], | ||
upsert: bool = False, | ||
bypass_document_validation: bool = False, | ||
bypass_document_validation: Optional[bool] = None, | ||
collation: Optional[_CollationIn] = None, | ||
hint: Optional[_IndexKeyHint] = None, | ||
session: Optional[AsyncClientSession] = None, | ||
|
@@ -1237,7 +1237,7 @@ async def update_one( | |
filter: Mapping[str, Any], | ||
update: Union[Mapping[str, Any], _Pipeline], | ||
upsert: bool = False, | ||
bypass_document_validation: bool = False, | ||
bypass_document_validation: Optional[bool] = None, | ||
collation: Optional[_CollationIn] = None, | ||
array_filters: Optional[Sequence[Mapping[str, Any]]] = None, | ||
hint: Optional[_IndexKeyHint] = None, | ||
|
@@ -2948,11 +2948,12 @@ async def aggregate( | |
returning aggregate results using a cursor. | ||
- `collation` (optional): An instance of | ||
:class:`~pymongo.collation.Collation`. | ||
- `bypassDocumentValidation` (bool): If ``True``, allows the | ||
write to opt-out of document level validation. | ||
|
||
|
||
:return: A :class:`~pymongo.asynchronous.command_cursor.AsyncCommandCursor` over the result | ||
set. | ||
|
||
.. versionchanged:: 4.1 | ||
Added ``comment`` parameter. | ||
Added ``let`` parameter. | ||
|
@@ -3356,7 +3357,13 @@ async def find_one_and_delete( | |
if comment is not None: | ||
kwargs["comment"] = comment | ||
return await self._find_and_modify( | ||
filter, projection, sort, let=let, hint=hint, session=session, **kwargs | ||
filter, | ||
projection, | ||
sort, | ||
let=let, | ||
hint=hint, | ||
session=session, | ||
**kwargs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this change intentional? It seems unneeded. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not intended, good catch. |
||
) | ||
|
||
async def find_one_and_replace( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
bypass_document_validation: Optional[bool],
the arg should still be required.