Skip to content

Commit

Permalink
DBManager: fix unicode error display table data (fix #13447)
Browse files Browse the repository at this point in the history
  • Loading branch information
brushtyler committed Sep 29, 2015
1 parent ece1169 commit 0c480a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion python/plugins/db_manager/db_plugins/data_model.py
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/db_manager/db_plugins/plugin.py
Expand Up @@ -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)
Expand Down

0 comments on commit 0c480a9

Please sign in to comment.