Problems with ODBC driver and pyodbc when query returns error

I’m trying the ODBC driver with pyodbc and I’ve found out that whenever the query I run is invalid for whatever reason (wrong table name, invalid query format, etc) I get a segmentation fault.
I’m guessing that the driver isn’t able to handle errors returned by Dremio. Valid queries run fine and return values.

I’ve tried this on Mac OS and in an Ubuntu docker container.

Example queries:
“select now()” -> runs fine
"select nowasdf()" -> segmentation fault
"select * from existing_source.existing_table" -> runs fine
"select * from existing_source.not_existing_table" -> segmentation fault
"invalid query" -> segmentation fault

Code:

import pyodbc

host = 'myhost
port = 31010
user = 'myuser’
password = ‘mypass’

connection = pyodbc.connect(“Driver={Dremio Connector};ConnectionType=Direct;HOST={%s};PORT={%d};AuthenticationType=Plain;UID={%s};PWD={%s}”
% (host, port, user, password),autocommit=True)

cursor = connection.cursor()

try:
cursor.execute(‘invalid query’)
data = cursor.fetchall()
print data
except Exception as e:
print e.message
finally:
cursor.close()
connection.close()

hey @juanchoverd we’re taking a look – thanks for the detailed steps. Can you share the version of the ODBC driver you are using?

I’m using the rpm from dremio.com/download dremio-odbc-1.3.14.1043-1.x86_64

@juanchoverd couple of questions to narrow down the issue:

  • If possible, could you see if issuing similar queries from a non-python based tools result in the same issue.
  • Could set driver logging to level 6 and share the driver logs. You can do this by modifying dremio.drillodbc.ini under /opt/dremio-odbc/lib64/
  • Could you share versions of Python, PYODBC, unixODBC/iODBC?

Python 2.7.12
pyodbc==4.0.21
unixODBC 2.3.1

I’ve tried using isql and all of the invalid queries return “[ISQL]ERROR: Could not SQLPrepare”. This is with the verbose flag. I’m not sure if that is how it is supposed to work of if it supposed to return more detailed errors like “Table not found”. Valid queries run fine.

I’ve attached the logs created after running the python script.

logs.zip (8.0 KB)

Thanks for the info @juanchoverd. We’ll reach out once we know more on the cause.

We haven’t fully identified the root cause, but it seems specific to pyodbc 4.0. If you have the opportunity, can you give pyodbc 3.x a chance? in our testing with it, error handling looked fine.

Laurent thank you for your help. I’ve tried pyodbc 3.1.1 and it works correctly in my Macbook but it still does not work on the Ubuntu container. It still throws a segmentation fault. I have also tried pyodbc 2.1.11 in the Ubuntu container and it doesn’t work either.