Skip to content

Commit 39eacd0

Browse files
authored
PYTHON-2988 Deprecate MongoClient max_bson_size/max_message_size/max_write_batch_size (#1096)
1 parent 4b47d47 commit 39eacd0

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

doc/api/pymongo/mongo_client.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
.. autoattribute:: is_primary
2323
.. autoattribute:: is_mongos
2424
.. autoattribute:: nodes
25-
.. autoattribute:: max_bson_size
26-
.. autoattribute:: max_message_size
27-
.. autoattribute:: max_write_batch_size
2825
.. autoattribute:: codec_options
2926
.. autoattribute:: read_preference
3027
.. autoattribute:: write_concern
@@ -50,3 +47,6 @@
5047
.. autoattribute:: max_idle_time_ms
5148
.. autoattribute:: local_threshold_ms
5249
.. autoattribute:: server_selection_timeout
50+
.. autoattribute:: max_bson_size
51+
.. autoattribute:: max_message_size
52+
.. autoattribute:: max_write_batch_size

doc/changelog.rst

+19
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ Deprecations
4242
Use :attr:`~pymongo.mongo_client.options.retry_writes` instead.
4343
- Deprecated :attr:`pymongo.mongo_client.MongoClient.retry_reads`.
4444
Use :attr:`~pymongo.mongo_client.options.retry_reads` instead.
45+
- Deprecated :attr:`pymongo.mongo_client.MongoClient.max_bson_size`,
46+
:attr:`pymongo.mongo_client.MongoClient.max_message_size`, and
47+
:attr:`pymongo.mongo_client.MongoClient.max_write_batch_size`. These helpers
48+
were incorrect when in ``loadBalanced=true mode`` and ambiguous in clusters
49+
with mixed versions. Use the `hello command`_ to get the authoritative
50+
value from the remote server instead. Code like this::
51+
52+
max_bson_size = client.max_bson_size
53+
max_message_size = client.max_message_size
54+
max_write_batch_size = client.max_write_batch_size
55+
56+
can be changed to this::
57+
58+
doc = client.admin.command('hello')
59+
max_bson_size = doc['maxBsonObjectSize']
60+
max_message_size = doc['maxMessageSizeBytes']
61+
max_write_batch_size = doc['maxWriteBatchSize']
62+
63+
.. _hello command: https://docs.mongodb.com/manual/reference/command/hello/
4564

4665
See the `PyMongo 3.13.0 release notes in JIRA`_ for the list of resolved issues
4766
in this release.

pymongo/mongo_client.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -1205,35 +1205,47 @@ def options(self):
12051205

12061206
@property
12071207
def max_bson_size(self):
1208-
"""The largest BSON object the connected server accepts in bytes.
1208+
"""**DEPRECATED**: The largest BSON object the connected server accepts in bytes.
12091209
12101210
If the client is not connected, this will block until a connection is
12111211
established or raise ServerSelectionTimeoutError if no server is
12121212
available.
1213+
1214+
.. versionchanged:: 3.13
1215+
Deprecated.
12131216
"""
1217+
warnings.warn("max_bson_size is Deprecated", DeprecationWarning, stacklevel=2)
12141218
return self._server_property("max_bson_size")
12151219

12161220
@property
12171221
def max_message_size(self):
1218-
"""The largest message the connected server accepts in bytes.
1222+
"""**DEPRECATED**: The largest message the connected server accepts in bytes.
12191223
12201224
If the client is not connected, this will block until a connection is
12211225
established or raise ServerSelectionTimeoutError if no server is
12221226
available.
1227+
1228+
.. versionchanged:: 3.13
1229+
Deprecated.
12231230
"""
1231+
warnings.warn("max_message_size is Deprecated", DeprecationWarning, stacklevel=2)
12241232
return self._server_property("max_message_size")
12251233

12261234
@property
12271235
def max_write_batch_size(self):
1228-
"""The maxWriteBatchSize reported by the server.
1236+
"""**DEPRECATED**: The maxWriteBatchSize reported by the server.
12291237
12301238
If the client is not connected, this will block until a connection is
12311239
established or raise ServerSelectionTimeoutError if no server is
12321240
available.
12331241
12341242
Returns a default value when connected to server versions prior to
12351243
MongoDB 2.6.
1244+
1245+
.. versionchanged:: 3.13
1246+
Deprecated.
12361247
"""
1248+
warnings.warn("max_write_batch_size is Deprecated", DeprecationWarning, stacklevel=2)
12371249
return self._server_property("max_write_batch_size")
12381250

12391251
@property

0 commit comments

Comments
 (0)