Skip to content
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

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

Closed
redbaron4 opened this issue Dec 26, 2024 · 2 comments · Fixed by elastic/elastic-transport-python#199

Comments

@redbaron4
Copy link

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

@pquentin
Copy link
Member

pquentin commented Jan 6, 2025

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.

@pquentin
Copy link
Member

pquentin commented Jan 7, 2025

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 a pull request may close this issue.

2 participants