tableau / server-client-python

A Python library for the Tableau Server REST API
https://tableau.github.io/server-client-python/
MIT License
657 stars 422 forks source link

Delete tag with special characters like '#' does not work #675

Open tv-terminator opened 4 years ago

tv-terminator commented 4 years ago

I found that if the tag contains encodable characters such as '#' (which is quite commonly used for tagging!), the delete tag request neither succeeds nor throws an exception.

https://github.com/tableau/server-client-python/blob/43e1b063d83d3271b262d02e94445a930c161cb6/tableauserverclient/server/endpoint/resource_tagger.py#L28

bcantoni commented 4 years ago

@tv-terminator there could be an issue there (I think we have or had a similar bug with encoding special characters). Can you give a fuller code snippet example of how you're trying to delete tags? Also what type of resource are the tags associated with?

tv-terminator commented 4 years ago

I have tried both workbooks & datasources; ended up with same result. Heres a full log with code:

`# w = workbook_item, t = tableau connection/hook

w=t.workbooks_get(get_by_content_url='POC')[0] w <tableauserverclient.models.workbook_item.WorkbookItem object at 0x7f1116314e10> w.tags set() w.tags.add('#test') w.tags {'#test'} t.workbooks_update(w) [2020-08-28 19:43:18,196] {{resource_tagger.py:47}} INFO - Updated tags to {'#test'} [2020-08-28 19:43:18,283] {{workbooks_endpoint.py:89}} INFO - Updated workbook item (ID: xxxxxx-xxxxxx-xxxxx-xxxxx) <tableauserverclient.models.workbook_item.WorkbookItem object at 0x7f1118fa3f28> w=t.workbooks_get(get_by_content_url='POC')[0] w.tags {'#test'} w.tags.remove('#test') w.tags set() t.workbooks_update(w) [2020-08-28 19:44:10,195] {{resource_tagger.py:47}} INFO - Updated tags to set() [2020-08-28 19:44:10,259] {{workbooks_endpoint.py:89}} INFO - Updated workbook item (ID: xxxxxx-xxxxxx-xxxxx-xxxxx) <tableauserverclient.models.workbook_item.WorkbookItem object at 0x7f1116f73400> w=t.workbooks_get(get_by_content_url='POC')[0] w.tags {'#test'} `

Works fine with a plain text tag: `

w.tags.add('test') w.tags {'#test', 'test'} t.workbooks_update(w) [2020-08-28 19:47:38,117] {{resource_tagger.py:47}} INFO - Updated tags to {'#test', 'test'} [2020-08-28 19:47:38,194] {{workbooks_endpoint.py:89}} INFO - Updated workbook item (ID: xxxxxx-xxxxxx-xxxxx-xxxxx) <tableauserverclient.models.workbook_item.WorkbookItem object at 0x7f1116791ba8> w=t.workbooks_get(get_by_content_url='POC')[0] w.tags {'#test', 'test'} w.tags.remove('test') w.tags {'#test'} t.workbooks_update(w) [2020-08-28 19:48:19,445] {{resource_tagger.py:47}} INFO - Updated tags to {'#test'} [2020-08-28 19:48:19,519] {{workbooks_endpoint.py:89}} INFO - Updated workbook item (ID: xxxxxx-xxxxxx-xxxxx-xxxxx) <tableauserverclient.models.workbook_item.WorkbookItem object at 0x7f1116bf1ac8> w=t.workbooks_get(get_by_content_url='POC')[0] w.tags {'#test'} `

bcantoni commented 4 years ago

Thanks @tv-terminator for the repro steps. I can confirm this is a bug and your pointer to resource_tagger.py is where we are not properly quoting the tag.

Adding new #test tag works, put method:

DEBUG:urllib3.connectionpool:https://10ax.online.tableau.com:443 "PUT /api/3.9/sites/MY-SITE-IT/workbooks/MY-WORKBOOK-ID/tags HTTP/1.1" 200 202

Deleting the #test tag does not work, delete method throws a 405 error because "#test" is dropped from the URL:

DEBUG:urllib3.connectionpool:https://10ax.online.tableau.com:443 "DELETE /api/3.9/sites/MY-SITE-IT/workbooks/MY-WORKBOOK-ID/tags/ HTTP/1.1" 405 377
DEBUG:tableau.endpoint:b'<?xml version=\'1.0\' encoding=\'UTF-8\'?><tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-3.9.xsd"><error code="405000"><summary>Method Not Allowed</summary><detail>The HTTP method \'DELETE\' is not supported for the given resource</detail></error></tsResponse>'

Trying to delete a tag foo#bar shows the similar issue, with everything from the pound sign being dropped in the URL resulting in a 404:

DEBUG:urllib3.connectionpool:https://10ax.online.tableau.com:443 "DELETE /api/3.9/sites/MY-SITE-IT/workbooks/MY-WORKBOOK-ID/tags/foo HTTP/1.1" 404 342
DEBUG:tableau.endpoint:b'<?xml version=\'1.0\' encoding=\'UTF-8\'?><tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-3.9.xsd"><error code="404007"><summary>Resource Not Found</summary><detail>Tag \'foo\' could not be found.</detail></error></tsResponse>'

There are a few other open bugs around attributes with special characters, so hopefully we can resolve some of these together.

tv-terminator commented 4 years ago

Awesome! Thanks @bcantoni !

bcantoni commented 4 years ago

Similar bugs related to encoding include #578, #516 and #418