-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-5344 and PYTHON-5403 Allow Instantiated MongoClients to Send Client Metadata On-Demand #2358
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
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b1899d6
WIP - sync test pass but not async..
sleepyStick e18737f
move test to correct folder
sleepyStick a17f6ef
Merge branch 'master' into PYTHON-5344
sleepyStick f9a097a
fix typing
sleepyStick 21c4eef
add another test
sleepyStick 9f9c9d8
update/add the new prose tests
sleepyStick 265ef3b
make public
sleepyStick 8a9c4cb
add async tests (PYTHON-5403)
sleepyStick a4d1116
fix import?
sleepyStick 42e4b81
Merge branch 'master' into PYTHON-5344
sleepyStick 92b3046
Merge branch 'master' into PYTHON-5344
sleepyStick 08dbbf7
add unified format support
sleepyStick c54a7da
pull unified test from spec repo
sleepyStick 1c835ae
address review
sleepyStick 082c4ab
add comment
sleepyStick 8c49277
address review pt1
sleepyStick 0217c9c
address review pt 2
sleepyStick c6a8975
address review pt3
sleepyStick 825f8ed
fix typing
sleepyStick f635625
Update changelog.rst
sleepyStick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ | |
from pymongo.asynchronous.database import AsyncDatabase | ||
from pymongo.asynchronous.encryption import AsyncClientEncryption | ||
from pymongo.asynchronous.helpers import anext | ||
from pymongo.driver_info import DriverInfo | ||
from pymongo.encryption_options import _HAVE_PYMONGOCRYPT | ||
from pymongo.errors import ( | ||
AutoReconnect, | ||
|
@@ -703,6 +704,7 @@ async def _collectionOperation_createChangeStream(self, target, *args, **kwargs) | |
async def _databaseOperation_runCommand(self, target, **kwargs): | ||
self.__raise_if_unsupported("runCommand", target, AsyncDatabase) | ||
# Ensure the first key is the command name. | ||
print(kwargs) | ||
blink1073 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ordered_command = SON([(kwargs.pop("command_name"), 1)]) | ||
ordered_command.update(kwargs["command"]) | ||
kwargs["command"] = ordered_command | ||
|
@@ -840,6 +842,13 @@ async def _cursor_close(self, target, *args, **kwargs): | |
self.__raise_if_unsupported("close", target, NonLazyCursor, AsyncCommandCursor) | ||
return await target.close() | ||
|
||
async def _clientOperation_appendMetadata(self, target, *args, **kwargs): | ||
print("IN MY FUNC") | ||
print(kwargs) | ||
info_opts = kwargs["driver_info_options"] | ||
driver_info = DriverInfo(info_opts["name"], info_opts["version"], info_opts["platform"]) | ||
target.append_metadata(driver_info) | ||
|
||
async def _clientEncryptionOperation_createDataKey(self, target, *args, **kwargs): | ||
if "opts" in kwargs: | ||
kwargs.update(camel_to_snake_args(kwargs.pop("opts"))) | ||
|
@@ -925,11 +934,11 @@ async def run_entity_operation(self, spec): | |
) | ||
else: | ||
arguments = {} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whitespace removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops accident! |
||
if isinstance(target, AsyncMongoClient): | ||
method_name = f"_clientOperation_{opname}" | ||
elif isinstance(target, AsyncDatabase): | ||
method_name = f"_databaseOperation_{opname}" | ||
print(f"{method_name=}") | ||
elif isinstance(target, AsyncCollection): | ||
method_name = f"_collectionOperation_{opname}" | ||
# contentType is always stored in metadata in pymongo. | ||
|
@@ -976,6 +985,7 @@ async def run_entity_operation(self, spec): | |
with pymongo.timeout(timeout): | ||
result = await cmd(**dict(arguments)) | ||
else: | ||
print(f"{cmd=} {dict=} {arguments=}") | ||
result = await cmd(**dict(arguments)) | ||
except Exception as exc: | ||
# Ignore all operation errors but to avoid masking bugs don't | ||
|
@@ -1238,6 +1248,7 @@ async def run_special_operation(self, spec): | |
|
||
async def run_operations(self, spec): | ||
for op in spec: | ||
print(f"{op=}") | ||
if op["object"] == "testRunner": | ||
await self.run_special_operation(op) | ||
else: | ||
|
@@ -1440,6 +1451,7 @@ async def _run_scenario(self, spec, uri=None): | |
await self.check_log_messages(spec["operations"], expect_log_messages) | ||
else: | ||
# process operations | ||
print(f"{spec['operations']=}") | ||
await self.run_operations(spec["operations"]) | ||
|
||
# process expectEvents | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"description": "client metadata is not propagated to the server", | ||
"schemaVersion": "1.9", | ||
"runOnRequirements": [ | ||
{ | ||
"minServerVersion": "6.0" | ||
} | ||
], | ||
"createEntities": [ | ||
{ | ||
"client": { | ||
"id": "client", | ||
"observeEvents": [ | ||
"commandSucceededEvent", | ||
"commandFailedEvent", | ||
"connectionClosedEvent", | ||
"connectionCreatedEvent" | ||
] | ||
} | ||
}, | ||
{ | ||
"database": { | ||
"id": "database", | ||
"client": "client", | ||
"databaseName": "test" | ||
} | ||
} | ||
], | ||
"tests": [ | ||
{ | ||
"description": "metadata append does not create new connections or close existing ones and no hello command is sent", | ||
"operations": [ | ||
{ | ||
"name": "runCommand", | ||
"object": "database", | ||
"arguments": { | ||
"commandName": "ping", | ||
"command": { | ||
"ping": 1 | ||
} | ||
}, | ||
"expectResult": { | ||
"ok": 1 | ||
} | ||
}, | ||
{ | ||
"name": "appendMetadata", | ||
"object": "client", | ||
"arguments": { | ||
"driverInfoOptions": { | ||
"name": "framework", | ||
"version": "2.0", | ||
"platform": "Framework Platform" | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "runCommand", | ||
"object": "database", | ||
"arguments": { | ||
"commandName": "ping", | ||
"command": { | ||
"ping": 1 | ||
} | ||
}, | ||
"expectResult": { | ||
"ok": 1 | ||
} | ||
} | ||
], | ||
"expectEvents": [ | ||
{ | ||
"client": "client", | ||
"eventType": "cmap", | ||
"events": [ | ||
{ | ||
"connectionCreatedEvent": {} | ||
} | ||
] | ||
}, | ||
{ | ||
"client": "client", | ||
"eventType": "command", | ||
"events": [ | ||
{ | ||
"commandSucceededEvent": { | ||
"commandName": "ping" | ||
} | ||
}, | ||
{ | ||
"commandSucceededEvent": { | ||
"commandName": "ping" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.