Crash in PyXB when attempting to retrieve Unicode value from exception
Brought to you by:
pabigot
pyxb/exceptions_.py contains the following function::
def __str__ (self):
"""Override to use the system-provided message, if available."""
if self.__message is not None:
return '%s: %s' % (type(self).__name__, self.__message)
return exceptions.Exception.__str__(self)
After calling CreateFromDocument() with an invalid XML document that contains Unicode, PyXB may raise an exception that contains Unicode, such as:
BadTypeValueError(u'pattern violation for <unicode characters here> in MyType',)
When attempting to retrieve the value of the exception, "exceptions.Exception.str(self)" throws an exception:
File "/usr/local/lib/python2.6/dist-packages/pyxb/exceptions_.py" in __str__
48. return exceptions.Exception.__str__(self)
Exception Type: UnicodeEncodeError
Exception Value: 'ascii' codec can't encode character u'\xe9' in position 81: ordinal not in range(128)
I have not been able to find a workaround that would enable me to get even an ASCII version of the exception value.
(I removed the actual Unicode characters because Trac can't handle them.)
Fix reported bug
AFAICT nobody uses message, so I've removed the feature allowing the underlying Python exception message infrastructure to provide access to the message. Depending on your Python version you may still have issues (see http://bugs.python.org/issue2517), but at least PyXB shouldn't be getting in the way anymore.
The fix is in the next branch of the git repository, or try the patch attached to this ticket.
One of my documents contains a field, which is checked against a pattern.
When I put a UTF-8 character into the field, I should have gotten a ValidationError, but I got, when calling pyxb.ValidationError.details():
My calling code:
I'm using Python 2.7. I don't think this is a Python issue.
Please do not re-open closed tickets when reporting a new issue in new code. Especially do not change the metadata associated with the closed ticket.
I've moved this to #190.