Clean up workaround for sqlite opening errors

Now that we know the real cause, we can be a bit stricter with our workaround.
This commit is contained in:
Florian Bruhin 2018-09-12 10:48:43 +02:00
parent 59af280f5c
commit 91b8002dd5
2 changed files with 17 additions and 15 deletions

View File

@ -89,12 +89,13 @@ def raise_sqlite_error(msg, error):
"""Raise either a SqlBugError or SqlEnvironmentError."""
error_code = error.nativeErrorCode()
database_text = error.databaseText()
driver_text = error.driverText()
log.sql.debug("SQL error:")
log.sql.debug("type: {}".format(
debug.qenum_key(QSqlError, error.type())))
log.sql.debug("database text: {}".format(database_text))
log.sql.debug("driver text: {}".format(error.driverText()))
log.sql.debug("driver text: {}".format(driver_text))
log.sql.debug("error code: {}".format(error_code))
environmental_errors = [
@ -105,18 +106,15 @@ def raise_sqlite_error(msg, error):
SqliteErrorCode.FULL,
SqliteErrorCode.CANTOPEN,
]
# At least in init(), we can get errors like this:
# > type: ConnectionError
# > database text: out of memory
# > driver text: Error opening database
# > error code: -1
environmental_strings = [
"out of memory",
]
if (error_code in environmental_errors or
(error_code == SqliteErrorCode.UNKNOWN and
database_text in environmental_strings)):
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-70506
# We don't know what the actual error was, but let's assume it's not us to
# blame... Usually this is something like an unreadable database file.
qtbug_70506 = (error_code == SqliteErrorCode.UNKNOWN and
driver_text == "Error opening database" and
database_text == "out of memory")
if error_code in environmental_errors or qtbug_70506:
raise SqlEnvironmentError(msg, error)
else:
raise SqlBugError(msg, error)

View File

@ -49,9 +49,13 @@ class TestSqlError:
with pytest.raises(exception):
sql.raise_sqlite_error("Message", sql_err)
def test_out_of_memory(self):
"""On out of memory error, we get an error code '-1' from Qt."""
sql_err = QSqlError("driver text",
def test_qtbug_70506(self):
"""Test Qt's wrong handling of errors while opening the database.
Due to https://bugreports.qt.io/browse/QTBUG-70506 we get an error with
"out of memory" as string and -1 as error code.
"""
sql_err = QSqlError("Error opening database",
"out of memory",
QSqlError.UnknownError,
sql.SqliteErrorCode.UNKNOWN)