From 96c1746a66ba4f8ce905b2279af5a1cdae561d91 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 16 Sep 2025 05:29:24 -0500 Subject: [PATCH 1/9] wip --- pymongo/asynchronous/srv_resolver.py | 1 + pymongo/synchronous/srv_resolver.py | 1 + 2 files changed, 2 insertions(+) diff --git a/pymongo/asynchronous/srv_resolver.py b/pymongo/asynchronous/srv_resolver.py index 9d1b8fe141..fc61e0e191 100644 --- a/pymongo/asynchronous/srv_resolver.py +++ b/pymongo/asynchronous/srv_resolver.py @@ -113,6 +113,7 @@ async def get_options(self) -> Optional[str]: return (b"&".join([b"".join(res.strings) for res in results])).decode("utf-8") # type: ignore[attr-defined] async def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: + print(f"{self.__srv=} {self.__fqdn=}") # noqa: T201 try: results = await _resolve( "_" + self.__srv + "._tcp." + self.__fqdn, "SRV", lifetime=self.__connect_timeout diff --git a/pymongo/synchronous/srv_resolver.py b/pymongo/synchronous/srv_resolver.py index 0817c6dcd7..9552c67e4d 100644 --- a/pymongo/synchronous/srv_resolver.py +++ b/pymongo/synchronous/srv_resolver.py @@ -113,6 +113,7 @@ def get_options(self) -> Optional[str]: return (b"&".join([b"".join(res.strings) for res in results])).decode("utf-8") # type: ignore[attr-defined] def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: + print(f"{self.__srv=} {self.__fqdn=}") # noqa: T201 try: results = _resolve( "_" + self.__srv + "._tcp." + self.__fqdn, "SRV", lifetime=self.__connect_timeout From 16d41e64bb3f8ab35afa7bcffa1867b9a077dc1b Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 16 Sep 2025 05:51:38 -0500 Subject: [PATCH 2/9] change error raise --- pymongo/asynchronous/srv_resolver.py | 2 +- pymongo/synchronous/srv_resolver.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pymongo/asynchronous/srv_resolver.py b/pymongo/asynchronous/srv_resolver.py index fc61e0e191..d79738c082 100644 --- a/pymongo/asynchronous/srv_resolver.py +++ b/pymongo/asynchronous/srv_resolver.py @@ -113,7 +113,6 @@ async def get_options(self) -> Optional[str]: return (b"&".join([b"".join(res.strings) for res in results])).decode("utf-8") # type: ignore[attr-defined] async def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: - print(f"{self.__srv=} {self.__fqdn=}") # noqa: T201 try: results = await _resolve( "_" + self.__srv + "._tcp." + self.__fqdn, "SRV", lifetime=self.__connect_timeout @@ -123,6 +122,7 @@ async def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: # Raise the original error. raise # Else, raise all errors as ConfigurationError. + raise ValueError(f"{self.__srv=} {self.__fqdn=}") from None raise ConfigurationError(str(exc)) from None return results diff --git a/pymongo/synchronous/srv_resolver.py b/pymongo/synchronous/srv_resolver.py index 9552c67e4d..0490fe8c9d 100644 --- a/pymongo/synchronous/srv_resolver.py +++ b/pymongo/synchronous/srv_resolver.py @@ -113,7 +113,6 @@ def get_options(self) -> Optional[str]: return (b"&".join([b"".join(res.strings) for res in results])).decode("utf-8") # type: ignore[attr-defined] def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: - print(f"{self.__srv=} {self.__fqdn=}") # noqa: T201 try: results = _resolve( "_" + self.__srv + "._tcp." + self.__fqdn, "SRV", lifetime=self.__connect_timeout @@ -123,6 +122,7 @@ def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: # Raise the original error. raise # Else, raise all errors as ConfigurationError. + raise ValueError(f"{self.__srv=} {self.__fqdn=}") from None raise ConfigurationError(str(exc)) from None return results From ff83d014e5999071e38a9324727d117d202c68b8 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 16 Sep 2025 06:07:29 -0500 Subject: [PATCH 3/9] more debug --- pymongo/asynchronous/srv_resolver.py | 2 +- pymongo/synchronous/srv_resolver.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pymongo/asynchronous/srv_resolver.py b/pymongo/asynchronous/srv_resolver.py index d79738c082..138e126cb3 100644 --- a/pymongo/asynchronous/srv_resolver.py +++ b/pymongo/asynchronous/srv_resolver.py @@ -122,7 +122,7 @@ async def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: # Raise the original error. raise # Else, raise all errors as ConfigurationError. - raise ValueError(f"{self.__srv=} {self.__fqdn=}") from None + raise ValueError(f"{self.__srv=} {self.__fqdn=} {exc=}") from None raise ConfigurationError(str(exc)) from None return results diff --git a/pymongo/synchronous/srv_resolver.py b/pymongo/synchronous/srv_resolver.py index 0490fe8c9d..3411cd00a8 100644 --- a/pymongo/synchronous/srv_resolver.py +++ b/pymongo/synchronous/srv_resolver.py @@ -122,7 +122,7 @@ def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: # Raise the original error. raise # Else, raise all errors as ConfigurationError. - raise ValueError(f"{self.__srv=} {self.__fqdn=}") from None + raise ValueError(f"{self.__srv=} {self.__fqdn=} {exc=}") from None raise ConfigurationError(str(exc)) from None return results From 9029d23a21a2f14a0e50272a4c37b5bf3eaa50d3 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 16 Sep 2025 07:23:39 -0500 Subject: [PATCH 4/9] unmask dns error --- pymongo/asynchronous/srv_resolver.py | 13 ++++++------- pymongo/synchronous/srv_resolver.py | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/pymongo/asynchronous/srv_resolver.py b/pymongo/asynchronous/srv_resolver.py index 138e126cb3..d3da9c9bc4 100644 --- a/pymongo/asynchronous/srv_resolver.py +++ b/pymongo/asynchronous/srv_resolver.py @@ -93,8 +93,8 @@ def __init__( try: split_fqdn = self.__fqdn.split(".") self.__plist = split_fqdn[1:] if len(split_fqdn) > 2 else split_fqdn - except Exception: - raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from None + except Exception as exc: + raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from exc self.__slen = len(self.__plist) self.nparts = len(split_fqdn) @@ -107,7 +107,7 @@ async def get_options(self) -> Optional[str]: # No TXT records return None except Exception as exc: - raise ConfigurationError(str(exc)) from None + raise ConfigurationError(str(exc)) from exc if len(results) > 1: raise ConfigurationError("Only one TXT record is supported") return (b"&".join([b"".join(res.strings) for res in results])).decode("utf-8") # type: ignore[attr-defined] @@ -122,8 +122,7 @@ async def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: # Raise the original error. raise # Else, raise all errors as ConfigurationError. - raise ValueError(f"{self.__srv=} {self.__fqdn=} {exc=}") from None - raise ConfigurationError(str(exc)) from None + raise ConfigurationError(str(exc)) from exc return results async def _get_srv_response_and_hosts( @@ -146,8 +145,8 @@ async def _get_srv_response_and_hosts( ) try: nlist = srv_host.split(".")[1:][-self.__slen :] - except Exception: - raise ConfigurationError(f"Invalid SRV host: {node[0]}") from None + except Exception as exc: + raise ConfigurationError(f"Invalid SRV host: {node[0]}") from exc if self.__plist != nlist: raise ConfigurationError(f"Invalid SRV host: {node[0]}") if self.__srv_max_hosts: diff --git a/pymongo/synchronous/srv_resolver.py b/pymongo/synchronous/srv_resolver.py index 3411cd00a8..2a90fa025a 100644 --- a/pymongo/synchronous/srv_resolver.py +++ b/pymongo/synchronous/srv_resolver.py @@ -93,8 +93,8 @@ def __init__( try: split_fqdn = self.__fqdn.split(".") self.__plist = split_fqdn[1:] if len(split_fqdn) > 2 else split_fqdn - except Exception: - raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from None + except Exception as exc: + raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from exc self.__slen = len(self.__plist) self.nparts = len(split_fqdn) @@ -107,7 +107,7 @@ def get_options(self) -> Optional[str]: # No TXT records return None except Exception as exc: - raise ConfigurationError(str(exc)) from None + raise ConfigurationError(str(exc)) from exc if len(results) > 1: raise ConfigurationError("Only one TXT record is supported") return (b"&".join([b"".join(res.strings) for res in results])).decode("utf-8") # type: ignore[attr-defined] @@ -122,8 +122,7 @@ def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: # Raise the original error. raise # Else, raise all errors as ConfigurationError. - raise ValueError(f"{self.__srv=} {self.__fqdn=} {exc=}") from None - raise ConfigurationError(str(exc)) from None + raise ConfigurationError(str(exc)) from exc return results def _get_srv_response_and_hosts( @@ -146,8 +145,8 @@ def _get_srv_response_and_hosts( ) try: nlist = srv_host.split(".")[1:][-self.__slen :] - except Exception: - raise ConfigurationError(f"Invalid SRV host: {node[0]}") from None + except Exception as exc: + raise ConfigurationError(f"Invalid SRV host: {node[0]}") from exc if self.__plist != nlist: raise ConfigurationError(f"Invalid SRV host: {node[0]}") if self.__srv_max_hosts: From e2c745f4673e5ba29a99d5016d6053dee4038007 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 16 Sep 2025 10:58:04 -0500 Subject: [PATCH 5/9] get whole traceback --- pymongo/asynchronous/srv_resolver.py | 4 +++- pymongo/synchronous/srv_resolver.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pymongo/asynchronous/srv_resolver.py b/pymongo/asynchronous/srv_resolver.py index d3da9c9bc4..d758200c70 100644 --- a/pymongo/asynchronous/srv_resolver.py +++ b/pymongo/asynchronous/srv_resolver.py @@ -122,7 +122,9 @@ async def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: # Raise the original error. raise # Else, raise all errors as ConfigurationError. - raise ConfigurationError(str(exc)) from exc + import traceback + + raise ConfigurationError(traceback.format_exception(exc)) from exc return results async def _get_srv_response_and_hosts( diff --git a/pymongo/synchronous/srv_resolver.py b/pymongo/synchronous/srv_resolver.py index 2a90fa025a..4f2974b9bc 100644 --- a/pymongo/synchronous/srv_resolver.py +++ b/pymongo/synchronous/srv_resolver.py @@ -122,7 +122,9 @@ def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: # Raise the original error. raise # Else, raise all errors as ConfigurationError. - raise ConfigurationError(str(exc)) from exc + import traceback + + raise ConfigurationError(traceback.format_exception(exc)) from exc return results def _get_srv_response_and_hosts( From 41592d8101705010e3bf2f4e08085f4092df02f3 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 16 Sep 2025 14:24:30 -0500 Subject: [PATCH 6/9] fix traceback handling --- pymongo/asynchronous/srv_resolver.py | 4 +++- pymongo/synchronous/srv_resolver.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pymongo/asynchronous/srv_resolver.py b/pymongo/asynchronous/srv_resolver.py index d758200c70..4e2a8cb204 100644 --- a/pymongo/asynchronous/srv_resolver.py +++ b/pymongo/asynchronous/srv_resolver.py @@ -124,7 +124,9 @@ async def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: # Else, raise all errors as ConfigurationError. import traceback - raise ConfigurationError(traceback.format_exception(exc)) from exc + raise ConfigurationError( + traceback.format_exception(type(exc), exc, exc.__traceback__) + ) from exc return results async def _get_srv_response_and_hosts( diff --git a/pymongo/synchronous/srv_resolver.py b/pymongo/synchronous/srv_resolver.py index 4f2974b9bc..1d4b8e6d58 100644 --- a/pymongo/synchronous/srv_resolver.py +++ b/pymongo/synchronous/srv_resolver.py @@ -124,7 +124,9 @@ def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: # Else, raise all errors as ConfigurationError. import traceback - raise ConfigurationError(traceback.format_exception(exc)) from exc + raise ConfigurationError( + traceback.format_exception(type(exc), exc, exc.__traceback__) + ) from exc return results def _get_srv_response_and_hosts( From a5768869eb0fc990259356073e269ab1c7519c95 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 16 Sep 2025 15:52:53 -0500 Subject: [PATCH 7/9] switch to python 3.10 --- test/lambda/build_internal.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lambda/build_internal.sh b/test/lambda/build_internal.sh index fec488d32c..84423db4d1 100755 --- a/test/lambda/build_internal.sh +++ b/test/lambda/build_internal.sh @@ -1,5 +1,5 @@ #!/bin/bash -ex cd /src -PYTHON=/opt/python/cp39-cp39/bin/python +PYTHON=/opt/python/cp310-cp310/bin/python $PYTHON -m pip install -v -e . From 449e03c6545528af05e69a08b32e48dd82d0bb52 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 16 Sep 2025 16:59:44 -0500 Subject: [PATCH 8/9] update template --- test/lambda/template.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lambda/template.yaml b/test/lambda/template.yaml index 651ac4a8f8..11052f88dd 100644 --- a/test/lambda/template.yaml +++ b/test/lambda/template.yaml @@ -23,7 +23,7 @@ Resources: Variables: MONGODB_URI: !Ref MongoDbUri Handler: app.lambda_handler - Runtime: python3.9 + Runtime: python3.10 Architectures: - x86_64 Events: From 993addbd4f0b70548397385079215156b56eadce Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 16 Sep 2025 17:28:09 -0500 Subject: [PATCH 9/9] clean up srv resolver --- pymongo/asynchronous/srv_resolver.py | 10 +++------- pymongo/synchronous/srv_resolver.py | 10 +++------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/pymongo/asynchronous/srv_resolver.py b/pymongo/asynchronous/srv_resolver.py index 4e2a8cb204..8d0d40c276 100644 --- a/pymongo/asynchronous/srv_resolver.py +++ b/pymongo/asynchronous/srv_resolver.py @@ -93,8 +93,8 @@ def __init__( try: split_fqdn = self.__fqdn.split(".") self.__plist = split_fqdn[1:] if len(split_fqdn) > 2 else split_fqdn - except Exception as exc: - raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from exc + except Exception: + raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from None self.__slen = len(self.__plist) self.nparts = len(split_fqdn) @@ -122,11 +122,7 @@ async def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: # Raise the original error. raise # Else, raise all errors as ConfigurationError. - import traceback - - raise ConfigurationError( - traceback.format_exception(type(exc), exc, exc.__traceback__) - ) from exc + raise ConfigurationError(str(exc)) from exc return results async def _get_srv_response_and_hosts( diff --git a/pymongo/synchronous/srv_resolver.py b/pymongo/synchronous/srv_resolver.py index 1d4b8e6d58..f6e99a3ea8 100644 --- a/pymongo/synchronous/srv_resolver.py +++ b/pymongo/synchronous/srv_resolver.py @@ -93,8 +93,8 @@ def __init__( try: split_fqdn = self.__fqdn.split(".") self.__plist = split_fqdn[1:] if len(split_fqdn) > 2 else split_fqdn - except Exception as exc: - raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from exc + except Exception: + raise ConfigurationError(_INVALID_HOST_MSG % (fqdn,)) from None self.__slen = len(self.__plist) self.nparts = len(split_fqdn) @@ -122,11 +122,7 @@ def _resolve_uri(self, encapsulate_errors: bool) -> resolver.Answer: # Raise the original error. raise # Else, raise all errors as ConfigurationError. - import traceback - - raise ConfigurationError( - traceback.format_exception(type(exc), exc, exc.__traceback__) - ) from exc + raise ConfigurationError(str(exc)) from exc return results def _get_srv_response_and_hosts(