Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Elasticsearch 'urls' should accept dict (now throwing TypeError: unhashable type: 'dict') #277

@ferdynice

Description

@ferdynice

The Elasticsearch connection used internally by ElasticUtils supports two ways of configuration:

By string and by dict. Usually using string method is good enough, although some connections require passing a dict (for exampe with auth). At the moment, when you pass a dict, ElasticUtils throws TypeError: unhashable type: 'dict' because it tries to cache the connection.

A current workaround for now is to wrap the dict in tuple, so that the hash function succeeds. For example:

def es_url_to_dict(url):
    parse = urlparse(url)
    port = parse.port if parse.port else (80 if parse.scheme == 'http' else 443)
    use_ssl = port is 443
    host = {'host': parse.hostname,
            'port': port,
            'use_ssl': use_ssl,
            'http_auth': '%s:%s' % (parse.username, parse.password)}
    return tuple(sorted(host.items()))
ES_URLS = [es_url_to_dict(os.environ.get('ES_URL', 'http://localhost:9200'))]

With this you can configure urls like https://myuser:mypass@myhost

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions