From 51eb6b5e03fb14a22912927726087a5b68451820 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Mon, 1 Dec 2025 11:37:53 -0500 Subject: [PATCH 1/5] Include Beam version details in MongoDB handshake --- sdks/python/apache_beam/io/mongodbio.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdks/python/apache_beam/io/mongodbio.py b/sdks/python/apache_beam/io/mongodbio.py index e8602edd40cd..325da4d357c9 100644 --- a/sdks/python/apache_beam/io/mongodbio.py +++ b/sdks/python/apache_beam/io/mongodbio.py @@ -71,6 +71,7 @@ import logging import math import struct +from importlib import metadata from typing import Union import apache_beam as beam @@ -97,6 +98,7 @@ from pymongo import DESCENDING from pymongo import MongoClient from pymongo import ReplaceOne + from pymongo.driver_info import DriverInfo except ImportError: objectid = None json_util = None @@ -105,6 +107,7 @@ DESCENDING = -1 MongoClient = None ReplaceOne = None + DriverInfo = None _LOGGER.warning("Could not find a compatible bson package.") __all__ = ["ReadFromMongoDB", "WriteToMongoDB"] @@ -262,6 +265,7 @@ def __init__( self.projection = projection self.spec = extra_client_params self.bucket_auto = bucket_auto + self.client = MongoClient(self.uri, **self.spec, driver=DriverInfo("Apache Beam", metadata.version("apache-beam"))) def estimate_size(self): with MongoClient(self.uri, **self.spec) as client: From 2172bb6beedf11b3150cebbaf10f99cad2b2ba8a Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Mon, 1 Dec 2025 13:14:54 -0500 Subject: [PATCH 2/5] Linting --- sdks/python/apache_beam/io/mongodbio.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sdks/python/apache_beam/io/mongodbio.py b/sdks/python/apache_beam/io/mongodbio.py index 325da4d357c9..0fa6b160ac06 100644 --- a/sdks/python/apache_beam/io/mongodbio.py +++ b/sdks/python/apache_beam/io/mongodbio.py @@ -265,7 +265,11 @@ def __init__( self.projection = projection self.spec = extra_client_params self.bucket_auto = bucket_auto - self.client = MongoClient(self.uri, **self.spec, driver=DriverInfo("Apache Beam", metadata.version("apache-beam"))) + self.client = MongoClient( + self.uri, + **self.spec, + driver=DriverInfo("Apache Beam", metadata.version("apache-beam")) + ) def estimate_size(self): with MongoClient(self.uri, **self.spec) as client: From dcbcb38baa8ef48bb26d6a6b635bf75b30ff8f00 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Mon, 1 Dec 2025 13:28:02 -0500 Subject: [PATCH 3/5] Formatting --- sdks/python/apache_beam/io/mongodbio.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdks/python/apache_beam/io/mongodbio.py b/sdks/python/apache_beam/io/mongodbio.py index 0fa6b160ac06..2b7937ef9a82 100644 --- a/sdks/python/apache_beam/io/mongodbio.py +++ b/sdks/python/apache_beam/io/mongodbio.py @@ -268,8 +268,7 @@ def __init__( self.client = MongoClient( self.uri, **self.spec, - driver=DriverInfo("Apache Beam", metadata.version("apache-beam")) - ) + driver=DriverInfo("Apache Beam", metadata.version("apache-beam"))) def estimate_size(self): with MongoClient(self.uri, **self.spec) as client: From 98fcfcee33b361a69e44c188e5ce0f56b0220e17 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Mon, 1 Dec 2025 13:38:10 -0500 Subject: [PATCH 4/5] Use __version__ --- sdks/python/apache_beam/io/mongodbio.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdks/python/apache_beam/io/mongodbio.py b/sdks/python/apache_beam/io/mongodbio.py index 2b7937ef9a82..dab0ef34a6e1 100644 --- a/sdks/python/apache_beam/io/mongodbio.py +++ b/sdks/python/apache_beam/io/mongodbio.py @@ -71,7 +71,6 @@ import logging import math import struct -from importlib import metadata from typing import Union import apache_beam as beam @@ -268,7 +267,7 @@ def __init__( self.client = MongoClient( self.uri, **self.spec, - driver=DriverInfo("Apache Beam", metadata.version("apache-beam"))) + driver=DriverInfo("Apache Beam", beam.__version__)) def estimate_size(self): with MongoClient(self.uri, **self.spec) as client: From 8e72630ccb7efdfca53b83b4131466e8bbd707e2 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Mon, 1 Dec 2025 14:01:33 -0500 Subject: [PATCH 5/5] formatter --- sdks/python/apache_beam/io/mongodbio.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdks/python/apache_beam/io/mongodbio.py b/sdks/python/apache_beam/io/mongodbio.py index dab0ef34a6e1..b1971fcf8141 100644 --- a/sdks/python/apache_beam/io/mongodbio.py +++ b/sdks/python/apache_beam/io/mongodbio.py @@ -265,9 +265,9 @@ def __init__( self.spec = extra_client_params self.bucket_auto = bucket_auto self.client = MongoClient( - self.uri, - **self.spec, - driver=DriverInfo("Apache Beam", beam.__version__)) + self.uri, + **self.spec, + driver=DriverInfo("Apache Beam", beam.__version__)) def estimate_size(self): with MongoClient(self.uri, **self.spec) as client: