Skip to content

Commit aef08c6

Browse files
authored
Merge branch 'master' into PYTHON-5867
2 parents 34f3872 + fa3c077 commit aef08c6

4 files changed

Lines changed: 32 additions & 32 deletions

File tree

pymongo/asynchronous/pool.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,10 +1065,16 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
10651065
reason=_verbose_connection_error_reason(ConnectionClosedReason.ERROR),
10661066
error=ConnectionClosedReason.ERROR,
10671067
)
1068-
self._handle_connection_error(error)
10691068
if isinstance(error, (IOError, OSError, *SSLErrors)):
10701069
details = _get_timeout_details(self.opts)
1071-
_raise_connection_failure(self.address, error, timeout_details=details)
1070+
# Wrap to AutoReconnect/NetworkTimeout BEFORE labeling so the
1071+
# SystemOverloadedError label lands on the propagated exception.
1072+
try:
1073+
_raise_connection_failure(self.address, error, timeout_details=details)
1074+
except (AutoReconnect, NetworkTimeout) as wrapped:
1075+
self._handle_connection_error(wrapped)
1076+
raise
1077+
self._handle_connection_error(error)
10721078
raise
10731079

10741080
conn = AsyncConnection(networking_interface, self, self.address, conn_id, self.is_sdam) # type: ignore[arg-type]

pymongo/synchronous/pool.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,10 +1061,16 @@ def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> Connect
10611061
reason=_verbose_connection_error_reason(ConnectionClosedReason.ERROR),
10621062
error=ConnectionClosedReason.ERROR,
10631063
)
1064-
self._handle_connection_error(error)
10651064
if isinstance(error, (IOError, OSError, *SSLErrors)):
10661065
details = _get_timeout_details(self.opts)
1067-
_raise_connection_failure(self.address, error, timeout_details=details)
1066+
# Wrap to AutoReconnect/NetworkTimeout BEFORE labeling so the
1067+
# SystemOverloadedError label lands on the propagated exception.
1068+
try:
1069+
_raise_connection_failure(self.address, error, timeout_details=details)
1070+
except (AutoReconnect, NetworkTimeout) as wrapped:
1071+
self._handle_connection_error(wrapped)
1072+
raise
1073+
self._handle_connection_error(error)
10681074
raise
10691075

10701076
conn = Connection(networking_interface, self, self.address, conn_id, self.is_sdam) # type: ignore[arg-type]

test/asynchronous/test_encryption.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,6 +2207,13 @@ async def test_01_insert_encrypted_indexed_and_find(self):
22072207
self.assertEqual(docs[0]["encryptedIndexed"], val)
22082208

22092209
async def test_02_insert_encrypted_indexed_and_find_contention(self):
2210+
# setUp creates the collection with contention=0 (from encryptedFields.json).
2211+
# This test uses contention_factor=10, so recreate the collection with contention=10.
2212+
await self.db.drop_collection("explicit_encryption", encrypted_fields=self.encrypted_fields)
2213+
encrypted_fields = copy.deepcopy(self.encrypted_fields)
2214+
encrypted_fields["fields"][0]["queries"]["contention"] = 10
2215+
await self.db.command("create", "explicit_encryption", encryptedFields=encrypted_fields)
2216+
22102217
val = "encrypted indexed value"
22112218
contention = 10
22122219
for _ in range(contention):
@@ -2217,20 +2224,7 @@ async def test_02_insert_encrypted_indexed_and_find_contention(self):
22172224
{"encryptedIndexed": insert_payload}
22182225
)
22192226

2220-
find_payload = await self.client_encryption.encrypt(
2221-
val, Algorithm.INDEXED, self.key1_id, query_type=QueryType.EQUALITY, contention_factor=0
2222-
)
2223-
docs = (
2224-
await self.encrypted_client[self.db.name]
2225-
.explicit_encryption.find({"encryptedIndexed": find_payload})
2226-
.to_list()
2227-
)
2228-
2229-
self.assertLessEqual(len(docs), 10)
2230-
for doc in docs:
2231-
self.assertEqual(doc["encryptedIndexed"], val)
2232-
2233-
# Find with contention_factor will return all 10 documents.
2227+
# Find with matching contention_factor returns all 10 documents.
22342228
find_payload = await self.client_encryption.encrypt(
22352229
val,
22362230
Algorithm.INDEXED,

test/test_encryption.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,6 +2195,13 @@ def test_01_insert_encrypted_indexed_and_find(self):
21952195
self.assertEqual(docs[0]["encryptedIndexed"], val)
21962196

21972197
def test_02_insert_encrypted_indexed_and_find_contention(self):
2198+
# setUp creates the collection with contention=0 (from encryptedFields.json).
2199+
# This test uses contention_factor=10, so recreate the collection with contention=10.
2200+
self.db.drop_collection("explicit_encryption", encrypted_fields=self.encrypted_fields)
2201+
encrypted_fields = copy.deepcopy(self.encrypted_fields)
2202+
encrypted_fields["fields"][0]["queries"]["contention"] = 10
2203+
self.db.command("create", "explicit_encryption", encryptedFields=encrypted_fields)
2204+
21982205
val = "encrypted indexed value"
21992206
contention = 10
22002207
for _ in range(contention):
@@ -2205,20 +2212,7 @@ def test_02_insert_encrypted_indexed_and_find_contention(self):
22052212
{"encryptedIndexed": insert_payload}
22062213
)
22072214

2208-
find_payload = self.client_encryption.encrypt(
2209-
val, Algorithm.INDEXED, self.key1_id, query_type=QueryType.EQUALITY, contention_factor=0
2210-
)
2211-
docs = (
2212-
self.encrypted_client[self.db.name]
2213-
.explicit_encryption.find({"encryptedIndexed": find_payload})
2214-
.to_list()
2215-
)
2216-
2217-
self.assertLessEqual(len(docs), 10)
2218-
for doc in docs:
2219-
self.assertEqual(doc["encryptedIndexed"], val)
2220-
2221-
# Find with contention_factor will return all 10 documents.
2215+
# Find with matching contention_factor returns all 10 documents.
22222216
find_payload = self.client_encryption.encrypt(
22232217
val,
22242218
Algorithm.INDEXED,

0 commit comments

Comments
 (0)