Azure / azure-functions-python-worker

Python worker for Azure Functions.
http://aka.ms/azurefunctions
MIT License
335 stars 103 forks source link

[BUG] Azure Functions with Python 3.11 does not include ODBC Driver for SQL Server anymore #1317

Closed aersam closed 11 months ago

aersam commented 1 year ago

In Azure Functions up to 3.10, it's possible to use pyodbc or other odbc related Libraries with MS SQL Server because the image comes with ODBC Driver V17 shipped. This is really practical with Azure SQL! In 3.11 however, the ODBC driver is not preinstalled. It's trivial to repo if you install pyodbc:

@app.function_name("test_odbc")
@app.route("test_odbc_drivers")
def test_odbc_drivers(req: func.HttpRequest) -> func.HttpResponse:
    import pyodbc
    import json

    drvs = pyodbc.drivers()
    return func.HttpResponse(json.dumps(drvs))

In 3.10 this returns the MS SQL ODBC driver, in 3.11 an empty array only.

I would expect a recent version of the ODBC Driver for MS SQL to be shipped as it's the recommended way to access MS Sql Azure in a Python. I'm fine if it's Version 18 for Python 3.11 (or would even welcome it)

See also this comment

In general there seems to be little docs about such stuff, or only outdated one, see https://github.com/Azure/azure-functions-python-worker/wiki/Preinstalled-Python-Libraries

bhagyshricompany commented 1 year ago

@gavin-aguiar pls comment.

pdthummar commented 1 year ago

@aersam We provide the MS SQL Server ODBC 17 driver along with Python 3.11. Have you come across any functionality issues when using ODBC 17 with Python 3.11? Considering the possibility that Python 3.11 may have introduced changes in the way it loads shared libraries, which could potentially impact this behavior. Thanks

Jazzex commented 1 year ago

@pdthummar I have come across functionality issues. ODBC 17 is not included with the 3.11 image mcr.microsoft.com/azure-functions/python:4-python3.11. I've verified this by checking the drivers with the command pyodbc.drivers() while in the running container.

pdthummar commented 11 months ago

Thanks @aersam and @Jazzex. We've identified and addressed the issue, incorporating ODBC Driver 18 for Python 3.11, which will be part of the upcoming host release. To mitigate the issue until fix is deployed, I recommend downgrading the Python version to 3.10.