diff --git a/CHANGELOG.rst b/CHANGELOG.rst index deb854d2..3836b292 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 340d8d71..6928c6ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -110,6 +110,7 @@ addopts = "--tb native -v -r fxX" filterwarnings = [ "error::DeprecationWarning", "ignore::DeprecationWarning:sqlalchemy.testing.plugin.*", + "ignore::DeprecationWarning:sqlalchemy_exasol.*", ] [tool.black] diff --git a/sqlalchemy_exasol/pyodbc.py b/sqlalchemy_exasol/pyodbc.py index 5737b71c..6f4c0018 100644 --- a/sqlalchemy_exasol/pyodbc.py +++ b/sqlalchemy_exasol/pyodbc.py @@ -9,6 +9,7 @@ import logging import re import sys +from warnings import warn from packaging import version from sqlalchemy import sql @@ -20,6 +21,7 @@ EXADialect, EXAExecutionContext, ) +from sqlalchemy_exasol.warnings import SqlaExasolDeprecationWarning logger = logging.getLogger("sqlalchemy_exasol") @@ -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): diff --git a/sqlalchemy_exasol/turbodbc.py b/sqlalchemy_exasol/turbodbc.py index 3b09849a..5e402b3f 100644 --- a/sqlalchemy_exasol/turbodbc.py +++ b/sqlalchemy_exasol/turbodbc.py @@ -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: @@ -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") diff --git a/sqlalchemy_exasol/warnings.py b/sqlalchemy_exasol/warnings.py new file mode 100644 index 00000000..a5b22fe0 --- /dev/null +++ b/sqlalchemy_exasol/warnings.py @@ -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.""" diff --git a/test/unit/exasol/test_deprectation_warnings.py b/test/unit/exasol/test_deprectation_warnings.py new file mode 100644 index 00000000..f5b287b0 --- /dev/null +++ b/test/unit/exasol/test_deprectation_warnings.py @@ -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)