Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QA: Add EOL/deprecation warning about support for SQLAlchemy 1.3 #503

Merged
merged 1 commit into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changes for crate
Unreleased
==========

- Add deprecation warning about dropping support for SQLAlchemy 1.3 soon, it is
effectively EOL.


2022/12/08 0.29.0
Expand Down
20 changes: 19 additions & 1 deletion src/crate/client/sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,28 @@
from .dialect import CrateDialect
from .sa_version import SA_1_4, SA_VERSION

# SQLAlchemy 1.3 does not have the `exec_driver_sql` method.

if SA_VERSION < SA_1_4:
import textwrap
import warnings

# SQLAlchemy 1.3 is effectively EOL.
SA13_DEPRECATION_WARNING = textwrap.dedent("""
WARNING: SQLAlchemy 1.3 is effectively EOL.
hlcianfagna marked this conversation as resolved.
Show resolved Hide resolved

SQLAlchemy 1.3 is EOL since 2023-01-27.
Future versions of the CrateDB SQLAlchemy dialect will drop support for SQLAlchemy 1.3.
It is recommended that you transition to using SQLAlchemy 1.4 or 2.0:

- https://docs.sqlalchemy.org/en/14/changelog/migration_14.html
- https://docs.sqlalchemy.org/en/20/changelog/migration_20.html
""".lstrip("\n"))
Copy link
Member

@hammerhead hammerhead Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.0 was released stable last night, and 1.3 is now officially EOL as per the "release status" table on https://www.sqlalchemy.org/download.html.

Copy link
Member Author

@amotl amotl Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've adjusted the admonition text correspondingly, and asked you and @hlcianfagna for another review. Thanks in advance!

warnings.warn(message=SA13_DEPRECATION_WARNING, category=DeprecationWarning)

# SQLAlchemy 1.3 does not have the `exec_driver_sql` method, so add it.
monkeypatch_add_exec_driver_sql()


__all__ = [
CrateDialect,
]
2 changes: 2 additions & 0 deletions src/crate/client/sqlalchemy/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .array_test import SqlAlchemyArrayTypeTest
from .dialect_test import SqlAlchemyDialectTest
from .function_test import SqlAlchemyFunctionTest
from .warnings_test import SqlAlchemyWarningsTest


def test_suite():
Expand All @@ -38,4 +39,5 @@ def test_suite():
tests.addTest(makeSuite(SqlAlchemyDialectTest))
tests.addTest(makeSuite(SqlAlchemyFunctionTest))
tests.addTest(makeSuite(SqlAlchemyArrayTypeTest))
tests.addTest(makeSuite(SqlAlchemyWarningsTest))
return tests
33 changes: 33 additions & 0 deletions src/crate/client/sqlalchemy/tests/warnings_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8; -*-
import sys
import warnings
from unittest import TestCase, skipIf

from crate.client.sqlalchemy import SA_1_4, SA_VERSION
from crate.testing.util import ExtraAssertions


class SqlAlchemyWarningsTest(TestCase, ExtraAssertions):

@skipIf(SA_VERSION >= SA_1_4, "There is no deprecation warning for "
"SQLAlchemy 1.3 on higher versions")
def test_sa13_deprecation_warning(self):
"""
Verify that a `DeprecationWarning` is issued when running SQLAlchemy 1.3.

https://docs.python.org/3/library/warnings.html#testing-warnings
"""
with warnings.catch_warnings(record=True) as w:

# Cause all warnings to always be triggered.
warnings.simplefilter("always")

# Trigger a warning by importing the SQLAlchemy dialect module.
# Because it already has been loaded, unload it beforehand.
del sys.modules["crate.client.sqlalchemy"]
import crate.client.sqlalchemy # noqa: F401

# Verify details of the SA13 EOL/deprecation warning.
self.assertEqual(len(w), 1)
self.assertIsSubclass(w[-1].category, DeprecationWarning)
self.assertIn("SQLAlchemy 1.3 is effectively EOL.", str(w[-1].message))
20 changes: 20 additions & 0 deletions src/crate/testing/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ExtraAssertions:
"""
Additional assert methods for unittest.
- https://github.com/python/cpython/issues/71339
- https://bugs.python.org/issue14819
- https://bugs.python.org/file43047/extra_assertions.patch
"""

def assertIsSubclass(self, cls, superclass, msg=None):
try:
r = issubclass(cls, superclass)
except TypeError:
if not isinstance(cls, type):
self.fail(self._formatMessage(msg,
'%r is not a class' % (cls,)))
raise
if not r:
self.fail(self._formatMessage(msg,
'%r is not a subclass of %r' % (cls, superclass)))