[sqlalchemy] Avoid errors from auto explain query
To avoid error poup on incomplete queries, i.e. autocomplete table name
still partial
@@ -65,7 +65,7 @@ from string import Template
from django.core.cache import caches
from sqlalchemy import create_engine, inspect, Table, MetaData
-from sqlalchemy.exc import OperationalError, UnsupportedCompilationError, CompileError
+from sqlalchemy.exc import OperationalError, UnsupportedCompilationError, CompileError, ProgrammingError
from desktop.lib import export_csvxls
from desktop.lib.i18n import force_unicode
@@ -300,10 +300,14 @@ class SqlAlchemyApi(Api):
if self.options['url'].startswith('bigquery://'):
explanation = ''
else:
+ try:
result = connection.execute('EXPLAIN '+ statement)
-
explanation = "\n".join("{}: {},".format(k, v) for row in result for k, v in row.items())
-
+ except ProgrammingError:
+ pass
+ except Exception as e:
+ LOG.debug('')
+ raise e
return {
'status': 0,
'explanation': explanation,
