Skip to content

PYTHON-5059 Update default maxMessageSizeBytes and maxWriteBatchSize #2078

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

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pymongo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@

# Defaults until we connect to a server and get updated limits.
MAX_BSON_SIZE = 16 * (1024**2)
MAX_MESSAGE_SIZE: int = 2 * MAX_BSON_SIZE
MAX_MESSAGE_SIZE = 48 * 1000 * 1000
MIN_WIRE_VERSION = 0
MAX_WIRE_VERSION = 0
MAX_WRITE_BATCH_SIZE = 1000
MAX_WRITE_BATCH_SIZE = 100000

# What this version of PyMongo supports.
MIN_SUPPORTED_SERVER_VERSION = "4.0"
Expand Down
2 changes: 1 addition & 1 deletion pymongo/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def max_bson_size(self) -> int:

@property
def max_message_size(self) -> int:
return self._doc.get("maxMessageSizeBytes", 2 * self.max_bson_size)
return self._doc.get("maxMessageSizeBytes", common.MAX_MESSAGE_SIZE)

@property
def max_write_batch_size(self) -> int:
Expand Down
13 changes: 8 additions & 5 deletions test/test_server_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from bson.int64 import Int64
from bson.objectid import ObjectId
from pymongo import common
from pymongo.hello import Hello, HelloCompat
from pymongo.server_description import ServerDescription
from pymongo.server_type import SERVER_TYPE
Expand Down Expand Up @@ -132,11 +133,13 @@ def test_fields(self):
self.assertEqual(4, s.min_wire_version)
self.assertEqual(25, s.max_wire_version)

def test_default_max_message_size(self):
s = parse_hello_response({"ok": 1, HelloCompat.LEGACY_CMD: True, "maxBsonObjectSize": 2})

# Twice max_bson_size.
self.assertEqual(4, s.max_message_size)
def test_defaults(self):
s = parse_hello_response({"ok": 1, HelloCompat.LEGACY_CMD: True})
self.assertEqual(common.MAX_BSON_SIZE, s.max_bson_size)
self.assertEqual(common.MAX_MESSAGE_SIZE, s.max_message_size)
self.assertEqual(common.MIN_WIRE_VERSION, s.min_wire_version)
self.assertEqual(common.MAX_WIRE_VERSION, s.max_wire_version)
self.assertEqual(common.MAX_WRITE_BATCH_SIZE, s.max_write_batch_size)

def test_standalone(self):
s = parse_hello_response({"ok": 1, HelloCompat.LEGACY_CMD: True})
Expand Down
Loading