Skip to content

Commit 3db2688

Browse files
committed
PYTHON-2453 Document db.command interaction, requireApiVersion1, other improvements
1 parent a6002d3 commit 3db2688

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

.evergreen/config.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -2028,8 +2028,8 @@ axes:
20282028
- id: requireApiVersion
20292029
display_name: "requireApiVersion"
20302030
values:
2031-
- id: "requireApiVersion"
2032-
display_name: "requireApiVersion"
2031+
- id: "requireApiVersion1"
2032+
display_name: "requireApiVersion1"
20332033
tags: [ "requireApiVersion_tag" ]
20342034
variables:
20352035
REQUIRE_API_VERSION: "1"
@@ -2625,6 +2625,7 @@ buildvariants:
26252625
requireApiVersion: "*"
26262626
display_name: "requireApiVersion ${python-version}"
26272627
tasks:
2628+
# Versioned API was introduced in MongoDB 4.7
26282629
- "test-latest-standalone"
26292630

26302631
- matrix_name: "ocsp-test"

pymongo/database.py

+6
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,12 @@ def command(self, command, value=1, check=True,
704704
.. note:: :meth:`command` does **not** apply any custom TypeDecoders
705705
when decoding the command response.
706706
707+
.. note:: If this client has been configured to use MongoDB Versioned
708+
API (see :ref:`versioned-api-ref`), then :meth:`command` will
709+
automactically add API versioning options to the given command.
710+
Explicitly adding API versioning options in the command and
711+
declaring an API version on the client is not supported.
712+
707713
.. versionchanged:: 3.6
708714
Added ``session`` parameter.
709715

pymongo/server_api.py

+6
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ def deprecation_errors(self):
114114

115115

116116
def _add_to_command(cmd, server_api):
117+
"""Internal helper which adds API versioning options to a command.
118+
119+
:Parameters:
120+
- `cmd`: The command.
121+
- `server_api` (optional): A :class:`ServerApi` or ``None``.
122+
"""
117123
if not server_api:
118124
return
119125
cmd['apiVersion'] = server_api.version

test/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,9 @@ def sanitize_cmd(cmd):
779779
cp.pop('$db', None)
780780
cp.pop('$readPreference', None)
781781
cp.pop('lsid', None)
782-
# Versioned api parameters
783-
cp.pop('apiVersion', None)
782+
if MONGODB_API_VERSION:
783+
# Versioned api parameters
784+
cp.pop('apiVersion', None)
784785
# OP_MSG encoding may move the payload type one field to the
785786
# end of the command. Do the same here.
786787
name = next(iter(cp))

0 commit comments

Comments
 (0)