Compare commits
9 Commits
master
...
PYTHON-311
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
615be654cb | ||
|
|
a4f81bcd3a | ||
|
|
ef6e0f2bb4 | ||
|
|
7a2b04f3c2 | ||
|
|
74b67d0ffc | ||
|
|
6a690c970b | ||
|
|
a9e08d173b | ||
|
|
c3cc02ee37 | ||
|
|
ae63fbcda6 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,3 +15,4 @@ pymongo.egg-info/
|
||||
.tox
|
||||
mongocryptd.pid
|
||||
.idea/
|
||||
.nova/
|
||||
|
||||
@ -174,6 +174,7 @@ class _AggregationCommand(object):
|
||||
max_await_time_ms=self._max_await_time_ms,
|
||||
session=session,
|
||||
explicit_session=self._explicit_session,
|
||||
comment=self._options.get("comment"),
|
||||
)
|
||||
cmd_cursor._maybe_pin_connection(sock_info)
|
||||
return cmd_cursor
|
||||
|
||||
@ -2179,7 +2179,12 @@ class Collection(common.BaseObject, Generic[_DocumentType]):
|
||||
raise
|
||||
cursor = {"id": 0, "firstBatch": []}
|
||||
cmd_cursor = CommandCursor(
|
||||
coll, cursor, sock_info.address, session=session, explicit_session=explicit_session
|
||||
coll,
|
||||
cursor,
|
||||
sock_info.address,
|
||||
session=session,
|
||||
explicit_session=explicit_session,
|
||||
comment=cmd.get("comment"),
|
||||
)
|
||||
cmd_cursor._maybe_pin_connection(sock_info)
|
||||
return cmd_cursor
|
||||
|
||||
@ -43,6 +43,7 @@ class CommandCursor(Generic[_DocumentType]):
|
||||
max_await_time_ms: Optional[int] = None,
|
||||
session: Optional["ClientSession"] = None,
|
||||
explicit_session: bool = False,
|
||||
comment: Any = None,
|
||||
) -> None:
|
||||
"""Create a new command cursor."""
|
||||
self.__sock_mgr: Any = None
|
||||
@ -56,6 +57,7 @@ class CommandCursor(Generic[_DocumentType]):
|
||||
self.__session = session
|
||||
self.__explicit_session = explicit_session
|
||||
self.__killed = self.__id == 0
|
||||
self.__comment = comment
|
||||
if self.__killed:
|
||||
self.__end_session(True)
|
||||
|
||||
@ -224,6 +226,7 @@ class CommandCursor(Generic[_DocumentType]):
|
||||
self.__max_await_time_ms,
|
||||
self.__sock_mgr,
|
||||
False,
|
||||
self.__comment,
|
||||
)
|
||||
)
|
||||
else: # Cursor id is zero nothing else to return
|
||||
@ -314,6 +317,7 @@ class RawBatchCommandCursor(CommandCursor, Generic[_DocumentType]):
|
||||
max_await_time_ms: Optional[int] = None,
|
||||
session: Optional["ClientSession"] = None,
|
||||
explicit_session: bool = False,
|
||||
comment: Any = None,
|
||||
) -> None:
|
||||
"""Create a new cursor / iterator over raw batches of BSON data.
|
||||
|
||||
@ -332,6 +336,7 @@ class RawBatchCommandCursor(CommandCursor, Generic[_DocumentType]):
|
||||
max_await_time_ms,
|
||||
session,
|
||||
explicit_session,
|
||||
comment,
|
||||
)
|
||||
|
||||
def _unpack_response(
|
||||
|
||||
@ -1182,6 +1182,7 @@ class Cursor(Generic[_DocumentType]):
|
||||
self.__max_await_time_ms,
|
||||
self.__sock_mgr,
|
||||
self.__exhaust,
|
||||
self.__comment,
|
||||
)
|
||||
self.__send_message(g)
|
||||
|
||||
|
||||
@ -774,6 +774,7 @@ class Database(common.BaseObject, Generic[_DocumentType]):
|
||||
sock_info.address,
|
||||
session=tmp_session,
|
||||
explicit_session=session is not None,
|
||||
comment=cmd.get("comment"),
|
||||
)
|
||||
cmd_cursor._maybe_pin_connection(sock_info)
|
||||
return cmd_cursor
|
||||
|
||||
@ -220,13 +220,15 @@ def _gen_find_command(
|
||||
return cmd
|
||||
|
||||
|
||||
def _gen_get_more_command(cursor_id, coll, batch_size, max_await_time_ms):
|
||||
def _gen_get_more_command(cursor_id, coll, batch_size, max_await_time_ms, comment):
|
||||
"""Generate a getMore command document."""
|
||||
cmd = SON([("getMore", cursor_id), ("collection", coll)])
|
||||
if batch_size:
|
||||
cmd["batchSize"] = batch_size
|
||||
if max_await_time_ms is not None:
|
||||
cmd["maxTimeMS"] = max_await_time_ms
|
||||
if comment is not None:
|
||||
cmd["comment"] = comment
|
||||
return cmd
|
||||
|
||||
|
||||
@ -419,6 +421,7 @@ class _GetMore(object):
|
||||
"sock_mgr",
|
||||
"_as_command",
|
||||
"exhaust",
|
||||
"comment",
|
||||
)
|
||||
|
||||
name = "getMore"
|
||||
@ -436,6 +439,7 @@ class _GetMore(object):
|
||||
max_await_time_ms,
|
||||
sock_mgr,
|
||||
exhaust,
|
||||
comment,
|
||||
):
|
||||
self.db = db
|
||||
self.coll = coll
|
||||
@ -449,6 +453,7 @@ class _GetMore(object):
|
||||
self.sock_mgr = sock_mgr
|
||||
self._as_command = None
|
||||
self.exhaust = exhaust
|
||||
self.comment = comment
|
||||
|
||||
def namespace(self):
|
||||
return "%s.%s" % (self.db, self.coll)
|
||||
@ -471,9 +476,8 @@ class _GetMore(object):
|
||||
return self._as_command
|
||||
|
||||
cmd = _gen_get_more_command(
|
||||
self.cursor_id, self.coll, self.ntoreturn, self.max_await_time_ms
|
||||
self.cursor_id, self.coll, self.ntoreturn, self.max_await_time_ms, self.comment
|
||||
)
|
||||
|
||||
if self.session:
|
||||
self.session._apply_to(cmd, False, self.read_preference, sock_info)
|
||||
sock_info.add_server_api(cmd)
|
||||
|
||||
@ -1761,7 +1761,7 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]):
|
||||
"firstBatch": res["databases"],
|
||||
"ns": "admin.$cmd",
|
||||
}
|
||||
return CommandCursor(admin["$cmd"], cursor, None)
|
||||
return CommandCursor(admin["$cmd"], cursor, None, comment=comment)
|
||||
|
||||
def list_database_names(
|
||||
self,
|
||||
|
||||
@ -247,6 +247,92 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Test that comment is set on getMore",
|
||||
"runOnRequirements": [
|
||||
{
|
||||
"minServerVersion": "4.4.0",
|
||||
"topologies": [
|
||||
"single",
|
||||
"replicaset"
|
||||
]
|
||||
}
|
||||
],
|
||||
"operations": [
|
||||
{
|
||||
"name": "createChangeStream",
|
||||
"object": "collection0",
|
||||
"arguments": {
|
||||
"pipeline": [],
|
||||
"comment": "comment"
|
||||
},
|
||||
"saveResultAsEntity": "changeStream0"
|
||||
},
|
||||
{
|
||||
"name": "insertOne",
|
||||
"object": "collection0",
|
||||
"arguments": {
|
||||
"document": {
|
||||
"_id": 1,
|
||||
"a": 1
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "iterateUntilDocumentOrError",
|
||||
"object": "changeStream0"
|
||||
}
|
||||
],
|
||||
"expectEvents": [
|
||||
{
|
||||
"client": "client0",
|
||||
"events": [
|
||||
{
|
||||
"commandStartedEvent": {
|
||||
"command": {
|
||||
"aggregate": "collection0",
|
||||
"pipeline": [
|
||||
{
|
||||
"$changeStream": {}
|
||||
}
|
||||
],
|
||||
"comment": "comment"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"commandStartedEvent": {
|
||||
"command": {
|
||||
"insert": "collection0",
|
||||
"documents": [
|
||||
{
|
||||
"_id": 1,
|
||||
"a": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"commandStartedEvent": {
|
||||
"command": {
|
||||
"getMore": {
|
||||
"$$type": [
|
||||
"int",
|
||||
"long"
|
||||
]
|
||||
},
|
||||
"collection": "collection0",
|
||||
"comment": "comment"
|
||||
},
|
||||
"commandName": "getMore",
|
||||
"databaseName": "database0"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -327,10 +327,14 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "aggregate with comment does not set comment on getMore",
|
||||
"description": "aggregate with comment sets comment on getMore",
|
||||
"runOnRequirements": [
|
||||
{
|
||||
"minServerVersion": "3.6.0"
|
||||
"minServerVersion": "4.4.0",
|
||||
"topologies": [
|
||||
"single",
|
||||
"replicaset"
|
||||
]
|
||||
}
|
||||
],
|
||||
"operations": [
|
||||
@ -411,9 +415,7 @@
|
||||
},
|
||||
"collection": "coll0",
|
||||
"batchSize": 2,
|
||||
"comment": {
|
||||
"$$exists": false
|
||||
}
|
||||
"comment": "comment"
|
||||
},
|
||||
"commandName": "getMore",
|
||||
"databaseName": "aggregate-tests"
|
||||
@ -430,9 +432,7 @@
|
||||
},
|
||||
"collection": "coll0",
|
||||
"batchSize": 2,
|
||||
"comment": {
|
||||
"$$exists": false
|
||||
}
|
||||
"comment": "comment"
|
||||
},
|
||||
"commandName": "getMore",
|
||||
"databaseName": "aggregate-tests"
|
||||
|
||||
@ -142,7 +142,7 @@
|
||||
"description": "BulkWrite updateMany with let option unsupported (server-side error)",
|
||||
"runOnRequirements": [
|
||||
{
|
||||
"minServerVersion": "3.6.0",
|
||||
"minServerVersion": "4.2.0",
|
||||
"maxServerVersion": "4.9"
|
||||
}
|
||||
],
|
||||
|
||||
@ -144,7 +144,7 @@
|
||||
"description": "BulkWrite updateOne with let option unsupported (server-side error)",
|
||||
"runOnRequirements": [
|
||||
{
|
||||
"minServerVersion": "3.6.0",
|
||||
"minServerVersion": "4.2.0",
|
||||
"maxServerVersion": "4.9"
|
||||
}
|
||||
],
|
||||
|
||||
@ -195,10 +195,14 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "find with comment does not set comment on getMore",
|
||||
"description": "find with comment sets comment on getMore",
|
||||
"runOnRequirements": [
|
||||
{
|
||||
"minServerVersion": "3.6"
|
||||
"minServerVersion": "4.4.0",
|
||||
"topologies": [
|
||||
"single",
|
||||
"replicaset"
|
||||
]
|
||||
}
|
||||
],
|
||||
"operations": [
|
||||
@ -267,9 +271,7 @@
|
||||
},
|
||||
"collection": "coll0",
|
||||
"batchSize": 2,
|
||||
"comment": {
|
||||
"$$exists": false
|
||||
}
|
||||
"comment": "comment"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -284,9 +286,7 @@
|
||||
},
|
||||
"collection": "coll0",
|
||||
"batchSize": 2,
|
||||
"comment": {
|
||||
"$$exists": false
|
||||
}
|
||||
"comment": "comment"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1333,6 +1333,7 @@ class TestClient(IntegrationTest):
|
||||
None,
|
||||
None,
|
||||
False,
|
||||
None,
|
||||
),
|
||||
unpack_res=Cursor(client.pymongo_test.collection)._unpack_response,
|
||||
address=("not-a-member", 27017),
|
||||
|
||||
@ -1201,6 +1201,7 @@ class TestVersionedApiExamples(IntegrationTest):
|
||||
client = MongoClient(uri, server_api=ServerApi("1", deprecation_errors=True))
|
||||
# End Versioned API Example 4
|
||||
|
||||
@unittest.skip("PYTHON-3167 count has been added to API version 1")
|
||||
@client_context.require_version_min(4, 7)
|
||||
def test_versioned_api_migration(self):
|
||||
# SERVER-58785
|
||||
|
||||
@ -239,6 +239,7 @@ class TestCommandMonitoring(IntegrationTest):
|
||||
# Exhaust the cursor to avoid kill cursors.
|
||||
tuple(cursor)
|
||||
|
||||
@client_context.require_version_min(4, 4, 4)
|
||||
def test_find_options(self):
|
||||
query = dict(
|
||||
filter={},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user