Bug report #13650

DBManager BaseError should test for already unicode error messages

Added by Médéric RIBREUX over 8 years ago. Updated over 7 years ago.

Status:Closed
Priority:Normal
Assignee:Giuseppe Sucameli
Category:DB Manager
Affected QGIS version:master Regression?:No
Operating System:all Easy fix?:No
Pull Request or Patch supplied:Yes Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:21685

Description

Hello,

since 401f43c, there is the following error in the Oracle plugin of DBManager:

Traceback (most recent call last):
              File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\\db_manager\\db_model.py", line 422, in rowCount
                self._refreshIndex(parent, True)
              File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\\db_manager\\db_model.py", line 473, in _refreshIndex
                if item.populate():
              File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\\db_manager\\db_model.py", line 211, in populate
                for t in self.getItemData().tables():
              File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\\db_manager\\db_plugins\\plugin.py", line 563, in tables
                return self.database().tables(self)
              File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\\db_manager\\db_plugins\\plugin.py", line 501, in tables
                tables = self.connector.getTables(schema.name if schema else None, sys_tables)
              File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\\db_manager\\db_plugins\\oracle\\connector.py", line 332, in getTables
                vectors = self.getVectorTables(schema)
              File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\\db_manager\\db_plugins\\oracle\\connector.py", line 631, in getVectorTables
                table_name, geocol)
              File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\\db_manager\\db_plugins\\oracle\\connector.py", line 772, in getTableGeomTypes
                c = self._execute(None, query)
              File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\\db_manager\\db_plugins\\connector.py", line 83, in _execute
                raise DbError(e, sql)
              File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\\db_manager\\db_plugins\\plugin.py", line 63, in __init__
                BaseError.__init__(self, e)
              File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\\db_manager\\db_plugins\\plugin.py", line 40, in __init__
                msg = unicode(msg, 'utf-8', 'replace') # convert from utf8 and replace errors (if any)
            TypeError: decoding Unicode is not supported

and the plugin is broken on the first database error encoutered (because Oracle db_plugin use unicode for error messages).

To fix this, we just need to add a test for unicode (isinstance) in db_plugins/plugin.py:

class BaseError(Exception):

    """Base class for exceptions in the plugin.""" 

    def __init__(self, e):
        if isinstance(e, Exception):
            msg = e.args[0] if len(e.args) > 0 else ''
        else:
            msg = e

        if not isinstance(msg, unicode):
            msg = unicode(msg, 'utf-8', 'replace') # convert from utf8 and replace errors (if any)

As the release date is tomorrow, I think we should really add this fix before...

Associated revisions

Revision 339fd756
Added by Giuseppe Sucameli over 8 years ago

DBManager: merge PR2342 by medspx (fix #13650)

History

#1 Updated by Médéric RIBREUX over 8 years ago

I've made a PR ...

#2 Updated by Giuseppe Sucameli over 8 years ago

  • Status changed from Open to Closed

#3 Updated by Giuseppe Sucameli over 8 years ago

  • Resolution set to fixed/implemented

Unfortunately my first commit 87657f8 was ugly as I didn't save my changes before commit...
So when I saw your PR, I've merged it (see 339fd75655e). Thanks a lot.

Also available in: Atom PDF