elastic/elasticsearch-py

TypeError: cannot pickle 'SSLContext' object when more than one host is used in client configuration and SSL Workaround is enabled

Closed this issue · 2 comments

If we try to configure a client with workaround mentioned in #2716 (custom SSLContext to disable strict certificate validation) and there are multiple hosts, the following traceback is raised

File "env/lib/python3.13/site-packages/elasticsearch/_sync/client/__init__.py", line 402, in __init__
    _transport = transport_class(
        node_configs,
    ...<2 lines>...
        **transport_kwargs,
    )
  File "env/lib/python3.13/site-packages/elastic_transport/_transport.py", line 185, in __init__
    validate_sniffing_options(
    ~~~~~~~~~~~~~~~~~~~~~~~~~^
        node_configs=node_configs,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        sniff_callback=sniff_callback,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "env/lib/python3.13/site-packages/elastic_transport/_transport.py", line 538, in validate_sniffing_options
    warn_if_varying_node_config_options(node_configs)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "env/lib/python3.13/site-packages/elastic_transport/_transport.py", line 548, in warn_if_varying_node_config_options
    for k, v in dataclasses.asdict(node_config).items()
                ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "env/lib/python3.13/dataclasses.py", line 1359, in asdict
    return _asdict_inner(obj, dict_factory)
  File "env/lib/python3.13/dataclasses.py", line 1370, in _asdict_inner
    f.name: _asdict_inner(getattr(obj, f.name), dict)
            ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "env/lib/python3.13/dataclasses.py", line 1427, in _asdict_inner
    return copy.deepcopy(obj)
           ~~~~~~~~~~~~~^^^^^
  File "env/lib/python3.13/copy.py", line 152, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle 'SSLContext' object

There is no error if a single hosts is provided.

Tested on client versions 8.17.0 and 8.12.0 and elastic_transport version 8.12 and 8.15

Hello, and thank you for your report! Sorry for the delay during the holiday seasons.

The issue is that sniffing and custom SSLContext don't mix well together. I opened elastic/elastic-transport-python#199 to fix it.