GeezerVison is showing github.com — workbook filter fails with special characters. · Issue #1200 · tableau/server-client-python
workbook filter fails with special characters. #1200DescriptionDescribe the bug
If my workbook has special character in it, my filter fails. I'm currently working around this but hoping that it can be fixed.
Versions
Details of your environment, including:
- Tableau online
- Python version: 3.9.12
- tableauserverclient==0.23.4
To Reproduce
with server.auth.sign_in(tableau_auth):
wbs = server.workbooks.all()
wbs.filter(name="T(L-F,SZ&V-MY) - PC")
next(iter(wbs_iter)) # this will fail
Results
ServerResponseError:
400065: Bad Request
None
Activityjacalata commented on Mar 14, 2023 Unfortunately you can't represent some characters in a search, but you can replace them with a wildcard.
Specifically, I think it's "," and "&" that don't work. But this does:
` wb_name = "T(L-FSZV-MY) - PC"
print("Searching for " + wb_name + "")
for workbook in server.workbooks.filter(name=wb_name):
print(workbook.name, workbook.id)
`
produces:
Searching for T(L-F*SZ*V-MY) - PC
T(L-F,SZ&V-MY) - PC b5d8b87f-3a3c-4787-83d4-6fd5cc2664db
T(L-F^SZ|V-MY) - PC 44ea14d9-54e8-4b9f-9ec9-150fbea57b08
https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_concepts_filtering_and_sorting.htm#filter-expression-notes jacalata commented on Apr 12, 2023 Should make sure our docs mention this limitation and workaround. VDFaller commented on Apr 20, 2023 So would it make sense to add a replace_illegal_chars argument, hopefuly something pithier, to filter? I could try it if I get a hint or something. There's not a lot of doc strings in this repo.
Maybe here?
something like
def filter(self, *invalid, **kwargs):
if invalid:
raise RuntimeError(f"Only accepts keyword arguments.")
# special arg to allow for filtering on fields that contain illegal characters
replace_illegal_characters = kwargs.pop("replace_illegal_characters", False)
for kwarg_key, value in kwargs.items():
field_name, operator = self._parse_shorthand_filter(kwarg_key)
if replace_illegal_characters:
value = self._replace_illegal_characters(value)
self.request_options.filter.add(Filter(field_name, operator, value))
return self
def _replace_illegal_characters(self, value):
"""helper function to replace illegal characters in a string value for filtering"""
if isinstance(value, str):
return value.replace(",", "*").replace('&', '*')
return valuemtwalkup commented on Nov 16, 2023 Not sure if this applies here, but we've run into issues with commas in other queries. We got around them by replacing , with %5C%2C instead of just %2C. If I can figure out how to test a patch I may try it when I have some more time. mtwalkup commented on Nov 17, 2023 Disregard my last comment, I tried to make it work and forced a \ (%5C) before the comma still got a 400 error.
However; just wanted to also note I am getting this same problem with a job filter.
Edit: comma instead of command jacalata commented on Sep 20, 2024 We have a bunch of questions around filters, and will go through all of them to carefully document current behavior. that might turn into some work items if there are inconsistencies/gaps. github-actions commented on Aug 6, 2026 This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. If this is still relevant, please comment to keep it open.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|