Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when building xpath query #46

Closed
t8y8 opened this issue Jun 30, 2016 · 4 comments
Closed

Exception when building xpath query #46

t8y8 opened this issue Jun 30, 2016 · 4 comments
Assignees
Labels

Comments

@t8y8
Copy link
Contributor

t8y8 commented Jun 30, 2016

I managed to trigger this when downloading workbooks from alpo.

This was done against the HEAD of a local copy of #45

`Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/xml/etree/ElementPath.py", line 263, in iterfind
selector = _cache[cache_key]
KeyError: (".//metadata-record[@Class='column'][local-name='[Today's Date]']", None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "runner.py", line 30, in
fields = wb_model.datasources[0].fields
File "/Users/tdoyle/Documents/py/document-api-python/tableaudocumentapi/datasource.py", line 135, in fields
self._fields = self._get_all_fields()
File "/Users/tdoyle/Documents/py/document-api-python/tableaudocumentapi/datasource.py", line 141, in _get_all_fields
return collections.OrderedDict([(k, v) for k, v in column_objects])
File "/Users/tdoyle/Documents/py/document-api-python/tableaudocumentapi/datasource.py", line 141, in
return collections.OrderedDict([(k, v) for k, v in column_objects])
File "/Users/tdoyle/Documents/py/document-api-python/tableaudocumentapi/datasource.py", line 140, in
for xml in self._datasourceTree.findall('.//column'))
File "/Users/tdoyle/Documents/py/document-api-python/tableaudocumentapi/datasource.py", line 17, in _mapping_from_xml
metadata_record = root_xml.find(xpath)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/xml/etree/ElementTree.py", line 649, in find
return self._root.find(path, namespaces)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/xml/etree/ElementPath.py", line 298, in find
return next(iterfind(elem, path, namespaces), None)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/xml/etree/ElementPath.py", line 277, in iterfind
selector.append(ops[token[0]](next, token))
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/xml/etree/ElementPath.py", line 233, in prepare_predicate
raise SyntaxError("invalid predicate")
SyntaxError: invalid predicate`

@t8y8
Copy link
Contributor Author

t8y8 commented Jun 30, 2016

Looks like values can't have quotes for xpath in python.

From the docs: Selects all elements for which the given attribute has the given value. The value cannot contain quotes.

https://docs.python.org/3/library/xml.etree.elementtree.html#supported-xpath-syntax

@graysonarts
Copy link
Contributor

graysonarts commented Jul 1, 2016

Yup, I saw that when I was developing the xpath, but can't believe we don't encode the quote when writing out to the xml. I'll have to check for single quotes and revert to a more expensive search to get around this. I'll get this fixed in the morning. Can you send me the file where you ran into this? I'll turn it into a test case (after cleaning up any potential private information from it, of course)

@t8y8
Copy link
Contributor Author

t8y8 commented Jul 1, 2016

I found the twb (I'll send it to you offline until we can scrub it)

We do actually encode it: '[Today's Date]'

@graysonarts graysonarts added the bug label Jul 1, 2016
@graysonarts graysonarts self-assigned this Jul 1, 2016
@graysonarts
Copy link
Contributor

hah when I looked at that, it didn't include the & code and I was like "How is that even possible?" Okay so I'll need to add encoding step specifically for 's

graysonarts pushed a commit that referenced this issue Jul 1, 2016
)

Fixes #42 #46 
* Initial attempt at enabling reading the columns from the datasource
* Fixing pep8 errors for EOFEOL
* Changing to OrderedDict for getting columns
* Add documentation for the various column attributes
* rename column to field
* Fixed #46 encode apostrophes in field names
* Enable multilook up for Fields
* Rename properties on the field based on feedback given in #45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants