Skip to content

Commit

Permalink
SQL: Fix crash when psycopg2 not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Oct 15, 2019
1 parent ac2adab commit 781149e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Orange/data/sql/backend/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from contextlib import contextmanager
from time import time

from psycopg2 import Error # pylint: disable=import-error
from psycopg2 import Error, ProgrammingError # pylint: disable=import-error
from psycopg2.pool import ThreadedConnectionPool # pylint: disable=import-error

from Orange.data import ContinuousVariable, DiscreteVariable, StringVariable, TimeVariable
Expand Down Expand Up @@ -81,7 +81,7 @@ def execute_sql_query(self, query, params=None):
cur.execute(query, params)
yield cur
log.info("%.2f ms: %s", 1000 * (time() - t), utfquery)
except Error as ex:
except (Error, ProgrammingError) as ex:
raise BackendError(str(ex)) from ex
finally:
connection.commit()
Expand Down
3 changes: 1 addition & 2 deletions Orange/widgets/data/owsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ def get_table(self):
what = self.sql = self.sqltext.toPlainText()
self.table = "Custom SQL"
if self.materialize:
import psycopg2 # pylint: disable=import-error
if not self.materialize_table_name:
self.Error.connection(
"Specify a table name to materialize the query")
Expand All @@ -229,7 +228,7 @@ def get_table(self):
pass
with self.backend.execute_sql_query("ANALYZE " + self.materialize_table_name):
pass
except (psycopg2.ProgrammingError, BackendError) as ex:
except BackendError as ex:
self.Error.connection(str(ex))
return None

Expand Down

0 comments on commit 781149e

Please sign in to comment.