-
Type:
Build Failure
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Tests
-
None
-
Python Drivers
-
Not Needed
-
None
-
None
-
None
-
None
-
None
-
None
Name of Failure:
test.test_bson.TestBSON.test_encode_size_limit fails with MemoryError instead of the expected ValueError.
Link to task:
test-standard-v8.0-python3.15-sync-noauth-ssl-replica-set (execution 0)|https://spruce.corp.mongodb.com/task/mongo_python_driver_test_win32_test_standard_v8.0_python3.15_sync_noauth_ssl_replica_set1bb24c934407bead62045c5497af5b6f75b32e6a26_10_01_23_53_50/tests?execution=0&sorts=STATUS%3AASC
Context of when and why the failure occurred:
The test (from PYTHON-5996) needs ~3GiB peak memory (1GiB string + 1GiB UTF-8 copy + 1GiB encode buffer). On 4GB windows-64-vsMulti-small hosts, allocation fails before the size-limit check can raise the expected ValueError. Fails 38% of the time on test-win32 (8% across all variants) over the last 30 days.
Proposed fix: Skip the test on hosts with < 6GiB total memory.
It is also failing on the v4.18 branch, so we'll need to backport the fix.
Stack trace:
2026/10/01 19:26:54.319 FAILURE: MemoryError () 2026/10/01 19:26:54.319 self = <test.test_bson.TestBSON testMethod=test_encode_size_limit> 2026/10/01 19:26:54.319 @unittest.skipUnless(bson.has_c(), "This test requires the C extension") 2026/10/01 19:26:54.319 def test_encode_size_limit(self): 2026/10/01 19:26:54.319 # PYTHON-5996: encoding must raise when a document's encoded size 2026/10/01 19:26:54.319 # exceeds the BSON size limit. 2026/10/01 19:26:54.319 big_value = "a" * (1 << 30) 2026/10/01 19:26:54.319 with self.assertRaises(ValueError): 2026/10/01 19:26:54.319 > encode({"a": big_value, "b": big_value, "c": big_value}) 2026/10/01 19:26:54.319 test\test_bson.py:700: 2026/10/01 19:26:54.319 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 2026/10/01 19:26:54.319 if not isinstance(codec_options, CodecOptions): 2026/10/01 19:26:54.319 raise CODEC_OPTIONS_TYPE_ERROR 2026/10/01 19:26:54.319 2026/10/01 19:26:54.319 > return dict_to_bson(document, check_keys, codec_options) 2026/10/01 19:26:54.319 E MemoryError 2026/10/01 19:26:54.319 bson\_init_.py:1085: MemoryError