Python: Post build script fails, cannot open ODBC driver lib
Bug Report
- At what date and time did you most recently experience the problem?
2021-11-24 16:08:45 UTC
- Where did you experience the problem? E.g. Azure Web Apps, Azure Functions, Azure Container Registry, or offline use.
Azure Web Apps
- What happened?
I am deploying a Django app using zip deploy via VS Code. My POST_BUILD_SCRIPT_PATH setting points to a script, which runs a Django managemant command that requires access to an Azure SQL server. When the app is running, this DB connection works fine, but in the post build script it fails, apparently because pyodbc cannot open the ODBC driver lib. Is msodbcsql17 only available during normal run, and not during post build script execution?
I'm using django-mssql-backend with these DB settings:
DATABASES = {
"default": {
"ENGINE": "sql_server.pyodbc",
"NAME": "[our db name]",
"HOST": "[our db name].database.windows.net",
"PORT": 1433,
"USER": "[our username]",
"PASSWORD": "[our password]",
"OPTIONS": {
"driver": "ODBC Driver 17 for SQL Server",
},
}
}
- Do you have log output? Please include between the backticks:
Note: Database.connect() is an alias for pyodbc.connect().
2021-11-24T16:08:28.393Z - Executing post-build command...
2021-11-24T16:08:45.349Z - Traceback (most recent call last):
2021-11-24T16:08:45.375Z - File "/tmp/8d9af63794cf34a/antenv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
2021-11-24T16:08:45.392Z - self.connect()
2021-11-24T16:08:45.433Z - File "/tmp/8d9af63794cf34a/antenv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 195, in connect
2021-11-24T16:08:45.469Z - self.connection = self.get_new_connection(conn_params)
2021-11-24T16:08:45.484Z - File "/tmp/8d9af63794cf34a/antenv/lib/python3.8/site-packages/sql_server/pyodbc/base.py", line 312, in get_new_connection
2021-11-24T16:08:45.496Z - conn = Database.connect(connstr,
2021-11-24T16:08:45.510Z - pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")
Did some more debugging, and indeed it looks like the msodbcsql17 driver is not available during POST_BUILD_SCRIPT_PATH execution.
Output of odbcinst -j in post build script:
unixODBC 2.3.4
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/49fd7979a593f73ceb65650c/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
/etc/odbcinst.ini exists but is apparently empty. /opt/microsoft/msodbcsql17/lib64/, where the driver is located during normal run, does not yet exist.
So how can I remedy this? Is there a way to make sure msodbcsql17 is available when the post build script is executed?
Hello, did you ever manage to solve this? Experiencing the same issue.
@s-mccarthy No, I'm afraid I gave up on it, and instead refactored so I don't run anything requiring a DB connection in the post build script. Not the optimal solution, but that's life.
Thanks for the response!
We're closing this issue due to its age. If this is still impacting you please open a new issue and simply link back to this one.