-
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
Changes from 15 commits
b1899d6
e18737f
a17f6ef
f9a097a
21c4eef
9f9c9d8
265ef3b
8a9c4cb
a4d1116
42e4b81
92b3046
08dbbf7
c54a7da
1c835ae
082c4ab
8c49277
0217c9c
c6a8975
825f8ed
f635625
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,225 @@ | ||||||
# Copyright 2013-present MongoDB, Inc. | ||||||
# | ||||||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
# you may not use this file except in compliance with the License. | ||||||
# You may obtain a copy of the License at | ||||||
# | ||||||
# http://www.apache.org/licenses/LICENSE-2.0 | ||||||
# | ||||||
# Unless required by applicable law or agreed to in writing, software | ||||||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
# See the License for the specific language governing permissions and | ||||||
# limitations under the License. | ||||||
from __future__ import annotations | ||||||
|
||||||
import asyncio | ||||||
import os | ||||||
import pathlib | ||||||
import time | ||||||
import unittest | ||||||
from test.asynchronous import AsyncIntegrationTest | ||||||
from test.asynchronous.unified_format import generate_test_classes | ||||||
from test.utils_shared import CMAPListener | ||||||
from typing import Any, Optional | ||||||
|
||||||
import pytest | ||||||
|
||||||
from pymongo import AsyncMongoClient, MongoClient | ||||||
|
from pymongo import AsyncMongoClient, MongoClient | |
from pymongo import AsyncMongoClient |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is maxWireVersion=13
specified by the spec or by MockupDB?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its needed so that MockupDB would work(?) without specification, the maxWireVersion
is 6, and PyMongo raises a configuration error: pymongo.errors.ConfigurationError: Server at localhost:56617 reports wire version 0, but this version of PyMongo requires at least 7 (MongoDB 4.0).
blink1073 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we refactor this into an async_wait_until
with some predicate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec specifically stated to wait 5ms
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these clients should be created with one of our PyMongoTestCase
helpers, not raw AsyncMongoClient()
.
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, | ||
|
@@ -840,6 +841,11 @@ 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): | ||
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,7 +931,6 @@ 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): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update this docstring to follow our standard format (params, versionadded, etc...)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made my best attempt at it, but lmk if I was off / am still missing something / have it incorrectly formatted >.<