Skip to content

Commit

Permalink
Add deprectaion warnings for trubodbc and pyodbc (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoretti authored Feb 1, 2024
1 parent 2902482 commit 4459728
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Unreleased

🔧 Changed
-----------
- Added deprecation warnings for pyodbc and trubodbc dialects
- Made websockets the default way to use sqlalchemy with exasol
- Made pydobc an optional dependency

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ addopts = "--tb native -v -r fxX"
filterwarnings = [
"error::DeprecationWarning",
"ignore::DeprecationWarning:sqlalchemy.testing.plugin.*",
"ignore::DeprecationWarning:sqlalchemy_exasol.*",
]

[tool.black]
Expand Down
7 changes: 7 additions & 0 deletions sqlalchemy_exasol/pyodbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging
import re
import sys
from warnings import warn

from packaging import version
from sqlalchemy import sql
Expand All @@ -20,6 +21,7 @@
EXADialect,
EXAExecutionContext,
)
from sqlalchemy_exasol.warnings import SqlaExasolDeprecationWarning

logger = logging.getLogger("sqlalchemy_exasol")

Expand All @@ -30,6 +32,11 @@ class EXADialect_pyodbc(EXADialect, PyODBCConnector):
driver_version = None

def __init__(self, **kw):
message = (
"'pyodbc' support in 'sqlalchemy_exasol' is deprecated and will be removed. "
"Please switch to the websocket driver. See documentation for details."
)
warn(message, SqlaExasolDeprecationWarning)
super().__init__(**kw)

def get_driver_version(self, connection):
Expand Down
10 changes: 10 additions & 0 deletions sqlalchemy_exasol/turbodbc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import decimal
from warnings import warn

from sqlalchemy import types as sqltypes
from sqlalchemy import util

from sqlalchemy_exasol.base import EXADialect
from sqlalchemy_exasol.warnings import SqlaExasolDeprecationWarning

DEFAULT_CONNECTION_PARAMS = {
# always enable efficient conversion to Python types:
Expand Down Expand Up @@ -72,6 +74,14 @@ class EXADialect_turbodbc(EXADialect):

colspecs = {sqltypes.Numeric: _ExaDecimal, sqltypes.Integer: _ExaInteger}

def __init__(self, **kw):
message = (
"'turbodbc' support in 'sqlalchemy_exasol' is deprecated and will be removed. "
"Please switch to the websocket driver. See documentation for details."
)
warn(message, SqlaExasolDeprecationWarning)
super().__init__(**kw)

@classmethod
def dbapi(cls):
return __import__("turbodbc")
Expand Down
6 changes: 6 additions & 0 deletions sqlalchemy_exasol/warnings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class SqlaExasolWarning(UserWarning):
"""Base class for all warnings emited by sqlalchemy_exasol."""


class SqlaExasolDeprecationWarning(SqlaExasolWarning, DeprecationWarning):
"""Warning class for features that will be removed in future versions."""
12 changes: 12 additions & 0 deletions test/unit/exasol/test_deprectation_warnings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

from sqlalchemy_exasol.pyodbc import EXADialect_pyodbc
from sqlalchemy_exasol.turbodbc import EXADialect_turbodbc


@pytest.mark.parametrize(
"klass,kwargs", [(EXADialect_pyodbc, {}), (EXADialect_turbodbc, {})]
)
def test_deprectation_warnings(klass, kwargs):
with pytest.deprecated_call():
_ = EXADialect_pyodbc(**kwargs)

0 comments on commit 4459728

Please sign in to comment.