ZettaIO / cachet-client

A python 3.6+ client for the Cachet API : https://cachet-client.readthedocs.io/
MIT License
14 stars 8 forks source link

Cannot create component tags with list/set #18

Closed chanpl closed 3 years ago

chanpl commented 4 years ago

Hi,

According to the documentation, component tag is a type of Set. However, it doesn't work as expected.

>>> cli.components.create(name="test1", status=1, tags=set(["tag1", "tag2"]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/cachetclient/v1/components.py", line 188, in create
    'tags': tags,
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/cachetclient/base.py", line 136, in _create
    response = self._http.post(path, data=data)
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/cachetclient/httpclient.py", line 37, in post
    return self.request('POST', path, data=data)
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/cachetclient/httpclient.py", line 53, in request
    timeout=self.timeout,
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/requests/sessions.py", line 516, in request
    prep = self.prepare_request(req)
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/requests/sessions.py", line 459, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/requests/models.py", line 317, in prepare
    self.prepare_body(data, files, json)
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/requests/models.py", line 467, in prepare_body
    body = complexjson.dumps(json)
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/simplejson/__init__.py", line 395, in dumps
    return _default_encoder.encode(obj)
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/simplejson/encoder.py", line 296, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/simplejson/encoder.py", line 378, in iterencode
    return _iterencode(o, 0)
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/simplejson/encoder.py", line 273, in default
    o.__class__.__name__)
TypeError: Object of type set is not JSON serializable
>>> cli.components.create(name="test1", status=1, tags=["tag1", "tag2"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/cachetclient/v1/components.py", line 188, in create
    'tags': tags,
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/cachetclient/base.py", line 136, in _create
    response = self._http.post(path, data=data)
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/cachetclient/httpclient.py", line 37, in post
    return self.request('POST', path, data=data)
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/cachetclient/httpclient.py", line 60, in request
    response.raise_for_status()
  File "/home/user/devel/.tox/py36/lib/python3.6/site-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://swarm.imagine-sw.com:8400/status/api/v1/components
>>>
einarf commented 4 years ago

This is definitely a bit confusing. During creation it should accept a list of tag names. What version of cachet are you using?

chanpl commented 4 years ago

Hi einarf,

I am using Cachet 2.4.

einarf commented 3 years ago

This was definitely a really stupid mistake. The way we expose tags are also badly designed currently. We only expose the tag slug and not the actual tag name.

I think it might be better to solve this once and for all and do a 4.0 release.

einarf commented 3 years ago

4.0.x is now released with improved tag support