Benoss / django-elasticsearch-debug-toolbar

A Django Debug Toolbar panel for Elasticsearch
https://pypi.python.org/pypi/django-elasticsearch-debug-toolbar/
MIT License
29 stars 19 forks source link

ElasticQueryInfo.__init__ fails with a None body #5

Closed pquentin closed 9 years ago

pquentin commented 9 years ago

As you can see in Transform.perform_request from the Python elasticsearch client, body can be None. However, using a None body raises a TypeError in ElasticQueryInfo.__init__:

    def __init__(self, method, full_url, path, body, status_code, response, duration):
        self.method = method
        self.full_url = full_url
        self.path = path
        self.body = _pretty_json(body)
        self.status_code = status_code
        self.response = _pretty_json(response)
        self.duration = round(duration * 1000, 2)
>       self.hash = hashlib.md5(self.full_url + self.body).hexdigest()
E       TypeError: coercing to Unicode: need string or buffer, NoneType found

Among many options, you can use self.body if self.body else b''. However, do not use bytes(self.body) : it works in Python 2 (yields b'None') but fails with a TypeError in Python 3.

Benoss commented 9 years ago

1.0.3 should fix this