Skip to content

Commit 51eba7a

Browse files
committed
PYTHON-2453 Document db.command interaction, requireApiVersion1, other improvements
1 parent cfd91bd commit 51eba7a

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

.evergreen/config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,8 +2007,8 @@ axes:
20072007
- id: requireApiVersion
20082008
display_name: "requireApiVersion"
20092009
values:
2010-
- id: "requireApiVersion"
2011-
display_name: "requireApiVersion"
2010+
- id: "requireApiVersion1"
2011+
display_name: "requireApiVersion1"
20122012
tags: [ "requireApiVersion_tag" ]
20132013
variables:
20142014
REQUIRE_API_VERSION: "1"
@@ -2604,6 +2604,7 @@ buildvariants:
26042604
requireApiVersion: "*"
26052605
display_name: "requireApiVersion ${python-version}"
26062606
tasks:
2607+
# Versioned API was introduced in MongoDB 4.7
26072608
- "test-latest-standalone"
26082609

26092610
- matrix_name: "ocsp-test"

pymongo/database.py

Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,9 @@ def sanitize_cmd(cmd):
764764
cp.pop('$db', None)
765765
cp.pop('$readPreference', None)
766766
cp.pop('lsid', None)
767-
# Versioned api parameters
768-
cp.pop('apiVersion', None)
767+
if MONGODB_API_VERSION:
768+
# Versioned api parameters
769+
cp.pop('apiVersion', None)
769770
# OP_MSG encoding may move the payload type one field to the
770771
# end of the command. Do the same here.
771772
name = next(iter(cp))

0 commit comments

Comments
 (0)