Skip to content

Commit 18d82e0

Browse files
authored
Merge branch 'master' into PYTHON-4721
2 parents ed73e72 + a3bdc13 commit 18d82e0

30 files changed

+1085
-159
lines changed

pymongo/asynchronous/mongo_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,8 @@ def __del__(self) -> None:
11951195
ResourceWarning,
11961196
stacklevel=2,
11971197
)
1198-
except AttributeError:
1198+
except (AttributeError, TypeError):
1199+
# Ignore errors at interpreter exit.
11991200
pass
12001201

12011202
def _close_cursor_soon(

pymongo/message.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ def _gen_find_command(
252252
if limit < 0:
253253
cmd["singleBatch"] = True
254254
if batch_size:
255+
# When limit and batchSize are equal we increase batchSize by 1 to
256+
# avoid an unnecessary killCursors.
257+
if limit == batch_size:
258+
batch_size += 1
255259
cmd["batchSize"] = batch_size
256260
if read_concern.level and not (session and session.in_transaction):
257261
cmd["readConcern"] = read_concern.document

pymongo/pool_options.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@
7070
"version": platform.mac_ver()[0],
7171
}
7272
elif sys.platform == "win32":
73+
_ver = sys.getwindowsversion()
7374
_METADATA["os"] = {
74-
"type": platform.system(),
75-
# "Windows XP", "Windows 7", "Windows 10", etc.
76-
"name": " ".join((platform.system(), platform.release())),
77-
"architecture": platform.machine(),
78-
# Windows patch level (e.g. 5.1.2600-SP3)
79-
"version": "-".join(platform.win32_ver()[1:3]),
75+
"type": "Windows",
76+
"name": "Windows",
77+
# Avoid using platform calls, see PYTHON-4455.
78+
"architecture": os.environ.get("PROCESSOR_ARCHITECTURE") or platform.machine(),
79+
# Windows patch level (e.g. 10.0.17763-SP0).
80+
"version": ".".join(map(str, _ver[:3])) + f"-SP{_ver[-1] or '0'}",
8081
}
8182
elif sys.platform.startswith("java"):
8283
_name, _ver, _arch = platform.java_ver()[-1]

pymongo/synchronous/mongo_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,8 @@ def __del__(self) -> None:
11931193
ResourceWarning,
11941194
stacklevel=2,
11951195
)
1196-
except AttributeError:
1196+
except (AttributeError, TypeError):
1197+
# Ignore errors at interpreter exit.
11971198
pass
11981199

11991200
def _close_cursor_soon(

requirements/typing.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mypy==1.13.0
2-
pyright==1.1.388
2+
pyright==1.1.389
33
typing_extensions
44
-r ./encryption.txt
55
-r ./ocsp.txt

test/asynchronous/test_retryable_writes.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2017 MongoDB, Inc.
1+
# Copyright 2017-present MongoDB, Inc.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -43,7 +43,6 @@
4343
from bson.int64 import Int64
4444
from bson.raw_bson import RawBSONDocument
4545
from bson.son import SON
46-
from pymongo.asynchronous.mongo_client import AsyncMongoClient
4746
from pymongo.errors import (
4847
AutoReconnect,
4948
ConnectionFailure,
@@ -226,47 +225,6 @@ async def test_supported_single_statement_no_retry(self):
226225
f"{msg} sent txnNumber with {event.command_name}",
227226
)
228227

229-
@async_client_context.require_no_standalone
230-
async def test_supported_single_statement_supported_cluster(self):
231-
for method, args, kwargs in retryable_single_statement_ops(self.db.retryable_write_test):
232-
msg = f"{method.__name__}(*{args!r}, **{kwargs!r})"
233-
self.listener.reset()
234-
await method(*args, **kwargs)
235-
commands_started = self.listener.started_events
236-
self.assertEqual(len(self.listener.succeeded_events), 1, msg)
237-
first_attempt = commands_started[0]
238-
self.assertIn(
239-
"lsid",
240-
first_attempt.command,
241-
f"{msg} sent no lsid with {first_attempt.command_name}",
242-
)
243-
initial_session_id = first_attempt.command["lsid"]
244-
self.assertIn(
245-
"txnNumber",
246-
first_attempt.command,
247-
f"{msg} sent no txnNumber with {first_attempt.command_name}",
248-
)
249-
250-
# There should be no retry when the failpoint is not active.
251-
if async_client_context.is_mongos or not async_client_context.test_commands_enabled:
252-
self.assertEqual(len(commands_started), 1)
253-
continue
254-
255-
initial_transaction_id = first_attempt.command["txnNumber"]
256-
retry_attempt = commands_started[1]
257-
self.assertIn(
258-
"lsid",
259-
retry_attempt.command,
260-
f"{msg} sent no lsid with {first_attempt.command_name}",
261-
)
262-
self.assertEqual(retry_attempt.command["lsid"], initial_session_id, msg)
263-
self.assertIn(
264-
"txnNumber",
265-
retry_attempt.command,
266-
f"{msg} sent no txnNumber with {first_attempt.command_name}",
267-
)
268-
self.assertEqual(retry_attempt.command["txnNumber"], initial_transaction_id, msg)
269-
270228
async def test_supported_single_statement_unsupported_cluster(self):
271229
if async_client_context.is_rs or async_client_context.is_mongos:
272230
raise SkipTest("This cluster supports retryable writes")

test/asynchronous/unified_format.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -545,15 +545,6 @@ def maybe_skip_test(self, spec):
545545
or "Cancel server check" in spec["description"]
546546
):
547547
self.skipTest("MMAPv1 does not support retryWrites=True")
548-
if (
549-
"AsyncDatabase-level aggregate with $out includes read preference for 5.0+ server"
550-
in spec["description"]
551-
):
552-
if async_client_context.version[0] == 8:
553-
self.skipTest("waiting on PYTHON-4356")
554-
if "Aggregate with $out includes read preference for 5.0+ server" in spec["description"]:
555-
if async_client_context.version[0] == 8:
556-
self.skipTest("waiting on PYTHON-4356")
557548
if "Client side error in command starting transaction" in spec["description"]:
558549
self.skipTest("Implement PYTHON-1894")
559550
if "timeoutMS applied to entire download" in spec["description"]:

test/crud/unified/client-bulkWrite-replaceOne-sort.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"schemaVersion": "1.4",
44
"runOnRequirements": [
55
{
6-
"minServerVersion": "8.0"
6+
"minServerVersion": "8.0",
7+
"serverless": "forbid"
78
}
89
],
910
"createEntities": [

test/crud/unified/client-bulkWrite-updateOne-sort.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"schemaVersion": "1.4",
44
"runOnRequirements": [
55
{
6-
"minServerVersion": "8.0"
6+
"minServerVersion": "8.0",
7+
"serverless": "forbid"
78
}
89
],
910
"createEntities": [

test/crud/unified/distinct-hint.json

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"description": "distinct-hint",
3+
"schemaVersion": "1.0",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "7.1.0"
7+
}
8+
],
9+
"createEntities": [
10+
{
11+
"client": {
12+
"id": "client0",
13+
"observeEvents": [
14+
"commandStartedEvent"
15+
]
16+
}
17+
},
18+
{
19+
"database": {
20+
"id": "database0",
21+
"client": "client0",
22+
"databaseName": "distinct-hint-tests"
23+
}
24+
},
25+
{
26+
"collection": {
27+
"id": "collection0",
28+
"database": "database0",
29+
"collectionName": "coll0"
30+
}
31+
}
32+
],
33+
"initialData": [
34+
{
35+
"collectionName": "coll0",
36+
"databaseName": "distinct-hint-tests",
37+
"documents": [
38+
{
39+
"_id": 1,
40+
"x": 11
41+
},
42+
{
43+
"_id": 2,
44+
"x": 22
45+
},
46+
{
47+
"_id": 3,
48+
"x": 33
49+
}
50+
]
51+
}
52+
],
53+
"tests": [
54+
{
55+
"description": "distinct with hint string",
56+
"operations": [
57+
{
58+
"name": "distinct",
59+
"object": "collection0",
60+
"arguments": {
61+
"fieldName": "x",
62+
"filter": {
63+
"_id": 1
64+
},
65+
"hint": "_id_"
66+
},
67+
"expectResult": [
68+
11
69+
]
70+
}
71+
],
72+
"expectEvents": [
73+
{
74+
"client": "client0",
75+
"events": [
76+
{
77+
"commandStartedEvent": {
78+
"command": {
79+
"distinct": "coll0",
80+
"key": "x",
81+
"query": {
82+
"_id": 1
83+
},
84+
"hint": "_id_"
85+
},
86+
"commandName": "distinct",
87+
"databaseName": "distinct-hint-tests"
88+
}
89+
}
90+
]
91+
}
92+
]
93+
},
94+
{
95+
"description": "distinct with hint document",
96+
"operations": [
97+
{
98+
"name": "distinct",
99+
"object": "collection0",
100+
"arguments": {
101+
"fieldName": "x",
102+
"filter": {
103+
"_id": 1
104+
},
105+
"hint": {
106+
"_id": 1
107+
}
108+
},
109+
"expectResult": [
110+
11
111+
]
112+
}
113+
],
114+
"expectEvents": [
115+
{
116+
"client": "client0",
117+
"events": [
118+
{
119+
"commandStartedEvent": {
120+
"command": {
121+
"distinct": "coll0",
122+
"key": "x",
123+
"query": {
124+
"_id": 1
125+
},
126+
"hint": {
127+
"_id": 1
128+
}
129+
},
130+
"commandName": "distinct",
131+
"databaseName": "distinct-hint-tests"
132+
}
133+
}
134+
]
135+
}
136+
]
137+
}
138+
]
139+
}

0 commit comments

Comments
 (0)