Skip to content

feat: Add mssql-python driver support with pyodbc fallback #379

feat: Add mssql-python driver support with pyodbc fallback

feat: Add mssql-python driver support with pyodbc fallback #379

---
name: Integration tests on Fabric DW
on: # yamllint disable-line rule:truthy
workflow_dispatch:
pull_request:
branches:
- main
jobs:
integration-tests-fabric-dw:
name: Integration (${{ matrix.python_version }}, ${{ matrix.driver_backend }})
strategy:
fail-fast: false
max-parallel: 2
matrix:
profile: ["integration_tests"]
python_version: ["3.10", "3.11", "3.12"]
driver_backend: ["mssql-python", "pyodbc"]
msodbc_version: ["18"]
runs-on: ubuntu-latest
permissions:
contents: read # Required to access repository files
packages: read # Grant explicit read access to packages
id-token: write # Needed if using OIDC authentication
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
- name: Install ODBC driver (pyodbc only)
if: matrix.driver_backend == 'pyodbc'
run: |
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql${{ matrix.msodbc_version }} unixodbc-dev
# Azure login using federated credentials
- name: Azure login with OIDC
uses: azure/login@v2
with:
client-id: ${{ secrets.DBT_AZURE_SP_NAME }}
tenant-id: ${{ secrets.DBT_AZURE_TENANT }}
allow-no-subscriptions: true
federated-token: true
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r dev_requirements.txt
if [ "${{ matrix.driver_backend }}" == "pyodbc" ]; then
pip install pyodbc>=5.2.0
fi
- name: Test Connection To Fabric Data Warehouse
id: fetch_token
run: |
pip install azure-identity azure-core
if [ "${{ matrix.driver_backend }}" == "pyodbc" ]; then
pip install pyodbc
fi
python - <<EOF
from azure.core.credentials import AccessToken
from azure.identity import DefaultAzureCredential
import logging
try:
credential = DefaultAzureCredential()
token = credential.get_token("https://database.windows.net/.default")
print(f"::set-output name=access_token::{token.token}")
except Exception as e:
logging.error("Error occurred while fetching token.", exc_info=True)
EOF
- name: Run functional tests
env:
DBT_AZURESQL_SERVER: ${{ secrets.DBT_AZURESQL_SERVER }}
DBT_AZURESQL_DB: ${{ secrets.DBT_AZURESQL_DB }}
FABRIC_INTEGRATION_TESTS_TOKEN: ${{ steps.fetch_token.outputs.access_token }}
FABRIC_TEST_DRIVER: 'ODBC Driver ${{ matrix.msodbc_version }} for SQL Server'
DBT_FABRIC_DRIVER_BACKEND: ${{ matrix.driver_backend }}
DBT_TEST_USER_1: dbo
DBT_TEST_USER_2: dbo
DBT_TEST_USER_3: dbo
run: pytest -ra -vv -x tests/functional --profile "${{ matrix.profile }}"