Skip to content

Conversation

blink1073
Copy link
Member

@blink1073 blink1073 commented Sep 16, 2025

Updated to use Python 3.10, which solved a dns resolve error on lambda.

I did not find the root cause, but since 3.9 is EOL next month I left it at this solution.

I also updated the errors raised by srv_resolver to include the original error, which was useful in debugging the problem.

Passing build: https://spruce.mongodb.com/task/mongo_python_driver_faas_lambda_test_aws_lambda_deployed_patch_eca38b730b8227c52cd5f0c655f617e969743ee1_68c9e481e31406000770e31e_25_09_16_22_28_25/logs?execution=0

@blink1073 blink1073 requested a review from a team as a code owner September 16, 2025 23:41
Copy link
Contributor

@aclark4life aclark4life left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@blink1073 blink1073 merged commit a7a645f into mongodb:master Sep 17, 2025
88 of 93 checks passed
@blink1073 blink1073 deleted the PYTHON-5555 branch September 17, 2025 11:39
@ShaneHarvey
Copy link
Member

I did not find the root cause, but since 3.9 is EOL next month I left it at this solution.

Did you find the full trackback of the unsupported operand type(s) for |: 'type' and 'NoneType' error? Sounds like some code is incorrectly using PEP-604 on Python 3.9.

@ShaneHarvey
Copy link
Member

Found in your patch:

[2025/09/16 12:41:50.285] {"errorMessage": "['Traceback (most recent call last):\\n',
 '  File \"/var/task/pymongo/synchronous/srv_resolver.py\", line 117, in _resolve_uri\\n    results = _resolve(\\n',
 '  File \"/var/task/pymongo/synchronous/srv_resolver.py\", line 51, in _resolve\\n    from dns import resolver\\n',
 '  File \"/var/task/dns/resolver.py\", line 30, in <module>\\n    import dns._ddr\\n',
 '  File \"/var/task/dns/_ddr.py\", line 9, in <module>\\n    import dns.asyncbackend\\n',
 '  File \"/var/task/dns/asyncbackend.py\", line 5, in <module>\\n    import dns.exception\\n',
 '  File \"/var/task/dns/exception.py\", line 28, in <module>\\n    class DNSException(Exception):\\n',
 '  File \"/var/task/dns/exception.py\", line 51, in DNSException\\n    msg: str | None = None  # non-parametrized message\\n',
 \"TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'\\n\"]", "errorType": "ConfigurationError", "requestId": "", "stackTrace": ["  File \"/var/lang/lib/python3.9/importlib/__init__.py\", line 127, in import_module\n    return _bootstrap._gcd_import(name[level:], package, level)\n",
 "  File \"<frozen importlib._bootstrap>\", line 1030, in _gcd_import\n",
 "  File \"<frozen importlib._bootstrap>\", line 1007, in _find_and_load\n",
 "  File \"<frozen importlib._bootstrap>\", line 986, in _find_and_load_unlocked\n",
 "  File \"<frozen importlib._bootstrap>\", line 680, in _load_unlocked\n",
 "  File \"<frozen importlib._bootstrap_external>\", line 850, in exec_module\n",
 "  File \"<frozen importlib._bootstrap>\", line 228, in _call_with_frames_removed\n",
 "  File \"/var/task/app.py\", line 119, in <module>\n    client.lambdaTest.list_collections()\n",
 "  File \"/var/task/pymongo/synchronous/database.py\", line 1182, in list_collections\n    return self._list_collections_helper(session, filter, comment, **kwargs)\n",
 "  File \"/var/task/pymongo/synchronous/database.py\", line 1143, in _list_collections_helper\n    return self._client._retryable_read(\n",
 "  File \"/var/task/pymongo/synchronous/mongo_client.py\", line 2047, in _retryable_read\n    return self._retry_internal(\n",
 "  File \"/var/task/pymongo/_csot.py\", line 125, in csot_wrapper\n    return func(self, *args, **kwargs)\n",
 "  File \"/var/task/pymongo/synchronous/mongo_client.py\", line 2003, in _retry_internal\n    return _ClientConnectionRetryable(\n",
 "  File \"/var/task/pymongo/synchronous/mongo_client.py\", line 2765, in run\n    return self._read() if self._is_read else self._write()\n",
 "  File \"/var/task/pymongo/synchronous/mongo_client.py\", line 2910, in _read\n    self._server = self._get_server()\n",
 "  File \"/var/task/pymongo/synchronous/mongo_client.py\", line 2858, in _get_server\n    return self._client._select_server(\n",
 "  File \"/var/task/pymongo/synchronous/mongo_client.py\", line 1820, in _select_server\n    topology = self._get_topology()\n",
 "  File \"/var/task/pymongo/synchronous/mongo_client.py\", line 1758, in _get_topology\n    self._resolve_srv()\n",
 "  File \"/var/task/pymongo/synchronous/mongo_client.py\", line 910, in _resolve_srv\n    res = uri_parser._parse_srv(\n",
 "  File \"/var/task/pymongo/synchronous/uri_parser.py\", line 168, in _parse_srv\n    nodes = dns_resolver.get_hosts()\n",
 "  File \"/var/task/pymongo/synchronous/srv_resolver.py\", line 161, in get_hosts\n    _, nodes = self._get_srv_response_and_hosts(True)\n",
 "  File \"/var/task/pymongo/synchronous/srv_resolver.py\", line 135, in _get_srv_response_and_hosts\n    results = self._resolve_uri(encapsulate_errors)\n",
 "  File \"/var/task/pymongo/synchronous/srv_resolver.py\", line 127, in _resolve_uri\n    raise ConfigurationError(\n"]}Exiting due to FunctionError!

It seems the task has installed dnspython 2.7.0:

 [2025/09/16 12:40:32.070] Collecting dnspython<3.0.0,>=1.16.0 (from pymongo==4.16.0.dev0)
 [2025/09/16 12:40:32.070]   Obtaining dependency information for dnspython<3.0.0,>=1.16.0 from https://files.pythonhosted.org/packages/68/1b/e0a87d256e40e8c888847551b20a017a6b98139178505dc7ffb96f04e954/dnspython-2.7.0-py3-none-any.whl.metadata
 [2025/09/16 12:40:32.092]   Downloading dnspython-2.7.0-py3-none-any.whl.metadata (5.8 kB)
 [2025/09/16 12:40:32.092] Downloading dnspython-2.7.0-py3-none-any.whl (313 kB)

But the AWS Function ends up using a later version of dnspython that has already dropped support for 3.9:

 '  File \"/var/task/dns/exception.py\", line 51, in DNSException\\n    msg: str | None = None  # non-parametrized message\\n',

https://spruce.mongodb.com/task/mongo_python_driver_faas_lambda_test_aws_lambda_deployed_patch_eca38b730b8227c52cd5f0c655f617e969743ee1_68c9b9854bb28a0007594d02_25_09_16_19_25_02/logs?execution=0

Whereas dnspython 2.7.0 looks like this:

    msg: Optional[str] = None  # non-parametrized message

https://github.com/rthalley/dnspython/blob/v2.7.0/dns/exception.py#L51

@blink1073
Copy link
Member Author

Thanks for tracking that down!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants