Skip to content
Permalink
Browse files

DBManager: fix unicode error display table data (fix #13447)

  • Loading branch information
brushtyler committed Sep 29, 2015
1 parent ece1169 commit 0c480a93c6ea453d79c7b0b0440ff1b3d4b3a0df
@@ -76,7 +76,11 @@ def data(self, index, role):
elif isinstance(val, (str, unicode)) and len(val) > 300:
# too much data to display, elide the string
return u"%s..." % val[:300]
return unicode(val) # convert to string
try:

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Sep 30, 2015

Member

Couldn't this be replaced with just a simple return unicode(val, 'utf-8', 'replace') instead of the whole try-catch thing?

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Sep 30, 2015

Member

Or maybe... would a repr(val) be more appropriate? (Not sure, just an idea...)

This comment has been minimized.

Copy link
@brushtyler

brushtyler Sep 30, 2015

Author Contributor

Yes, you're right, unicode(val, 'utf-8', 'replace') do the work.
About repr(val), it returns a string, not unicode, so IMHO we would get an error when wrapping the returned value within a unicode() call.

Probably we should also check return u"%s..." % val[:300], I guess it could raise the same error...

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Sep 30, 2015

Member

Yeah, it should be checked. And it would be nice to switch the % notation to the .format notation whenever working on it.

This comment has been minimized.

Copy link
@brushtyler

brushtyler Oct 4, 2015

Author Contributor

@m-kuhn unfortunately there was a reason that try block was there: http://hub.qgis.org/issues/13505 :(
I'm going to partially revert 401f43c

return unicode(val) # convert to unicode
except UnicodeDecodeError:
return unicode(val, 'utf-8', 'replace') # convert from utf8 and replace errors (if any)


def headerData(self, section, orientation, role):
if role != Qt.DisplayRole:
@@ -38,9 +38,9 @@ def __init__(self, e):
msg = e

try:
msg = unicode(msg)
msg = unicode(msg) # convert to unicode
except UnicodeDecodeError:
msg = unicode(msg, 'utf-8')
msg = unicode(msg, 'utf-8', 'replace') # convert from utf8 and replace errors (if any)

self.msg = msg
Exception.__init__(self, msg)

0 comments on commit 0c480a9

Please sign in to comment.
You can’t perform that action at this time.