-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-4298 Fix _apply_local_threshold TypeError #1566
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
Conversation
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.
Hi @Ale-Cas, thanks for the PR. Instead of silently ignoring this case, it would be great to detect when round_trip_time is None
and raise an informative error. Something like:
for server in selection.server_descriptions:
if server.round_trip_time is None:
raise ConfigurationError(f"round_trip_time for server {server.address} is unexpectedly None: {self}, servers: {selection.server_descriptions}")
The goal is to help us isolate the underlying problem. Are you able to reproduce this issue?
Based on this traceback: return [
> s for s in selection.server_descriptions if (s.round_trip_time - fastest) <= threshold
]
E TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType' This means that both >>> print(min([None, 1.0]))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'float' and 'NoneType'
>>> print(min([None]))
None |
Is your application using the "server_selector" argument to MongoClient? If so, could you share how it's defined?
|
Hi @ShaneHarvey thanks for the review, I'll address your suggestion and raise that exception.
No, we're not passing the server_selector argument in the client. This is the rest of the client configuration: pymongo.MongoClient(
self.config.connection_string,
connect=True,
tz_aware=True,
retryWrites=False,
retryReads=True,
minPoolSize=4,
maxPoolSize=100,
maxIdleTimeMS=3 * 60 * 1000,
socketTimeoutMS=8 * 1000,
connectTimeoutMS=8 * 1000,
serverSelectionTimeoutMS=29 * 1000,
) the application is also using a different session for each thread to perform any type of mongodb operation. That type error usually pops up during the CI, which is using this image ghcr.io/zcube/bitnami-compat/mongodb:6.0-debian-11-r64 to spin up a basic replica set (I can also share the mongo services we're using in docker compose if you think it's helpful). |
No, server_selector is a power-user type feature only useful in very niche circumstances.
Thanks! |
Hi @ShaneHarvey, I had again that error in the CI today, here's the full pymongo traceback:
|
@Ale-Cas I'm going to merge this after the test suite completes. Could you install this branch in your CI and provide us an example of the new exception? The new error will look something like:
|
@ShaneHarvey thanks for your help! And, as soon as I get the configuration error in the CI, I'll send it to you. |
Ideally we can debug this issue and fix the underlying bug before we release. I backported this commit to the v4.6 branch here: d6248e9 Can you install the backported commit like this? |
Fix for TypeError caused by substraction between nulls when round_trip_time is None
Jira ticket: https://jira.mongodb.org/browse/PYTHON-4298
Linked to previous PR #1361