diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2023-05-09 23:36:42 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2023-05-09 23:36:42 +0000 |
commit | 92e54a0e1c96cecd99397cb1aee9c3bb28f780c6 (patch) | |
tree | 6f164cfeed18fbb2833148c105c96f9c9d2fcc6d | |
parent | 2aba0ada168d0047d54c7a08b0ffdde3102b716b (diff) | |
parent | 2866272251637c0dd246c275cf04947849ea88b8 (diff) | |
download | alembic-92e54a0e1c96cecd99397cb1aee9c3bb28f780c6.tar.gz |
Merge "Fix compat issue with older SQLAlchemy versions." into main
-rw-r--r-- | alembic/testing/fixtures.py | 7 | ||||
-rw-r--r-- | alembic/testing/requirements.py | 2 | ||||
-rw-r--r-- | alembic/testing/util.py | 11 | ||||
-rw-r--r-- | alembic/util/__init__.py | 1 | ||||
-rw-r--r-- | alembic/util/sqla_compat.py | 26 | ||||
-rw-r--r-- | docs/build/unreleased/1109.rst | 1 | ||||
-rw-r--r-- | docs/build/unreleased/1237.rst | 9 |
7 files changed, 30 insertions, 27 deletions
diff --git a/alembic/testing/fixtures.py b/alembic/testing/fixtures.py index ef1c3bb..65f3a0a 100644 --- a/alembic/testing/fixtures.py +++ b/alembic/testing/fixtures.py @@ -28,7 +28,7 @@ from ..operations import Operations from ..util import sqla_compat from ..util.sqla_compat import create_mock_engine from ..util.sqla_compat import sqla_14 -from ..util.sqla_compat import sqla_1x +from ..util.sqla_compat import sqla_2 testing_config = configparser.ConfigParser() @@ -36,10 +36,7 @@ testing_config.read(["test.cfg"]) class TestBase(SQLAlchemyTestBase): - if sqla_1x: - is_sqlalchemy_future = False - else: - is_sqlalchemy_future = True + is_sqlalchemy_future = sqla_2 @testing.fixture() def ops_context(self, migration_context): diff --git a/alembic/testing/requirements.py b/alembic/testing/requirements.py index a4a6045..40de4cd 100644 --- a/alembic/testing/requirements.py +++ b/alembic/testing/requirements.py @@ -84,7 +84,7 @@ class SuiteRequirements(Requirements): @property def sqlalchemy_1x(self): return exclusions.skip_if( - lambda config: not util.sqla_1x, + lambda config: util.sqla_2, "SQLAlchemy 1.x test", ) diff --git a/alembic/testing/util.py b/alembic/testing/util.py index e65597d..4517a69 100644 --- a/alembic/testing/util.py +++ b/alembic/testing/util.py @@ -6,12 +6,13 @@ # the MIT License: http://www.opensource.org/licenses/mit-license.php from __future__ import annotations -import re import types from typing import Union from sqlalchemy.util import inspect_getfullargspec +from ..util import sqla_2 + def flag_combinations(*combinations): """A facade around @testing.combinations() oriented towards boolean @@ -114,17 +115,11 @@ def _safe_int(value: str) -> Union[int, str]: def testing_engine(url=None, options=None, future=False): from sqlalchemy.testing import config from sqlalchemy.testing.engines import testing_engine - from sqlalchemy import __version__ - - _vers = tuple( - [_safe_int(x) for x in re.findall(r"(\d+|[abc]\d)", __version__)] - ) - sqla_1x = _vers < (2,) if not future: future = getattr(config._current.options, "future_engine", False) - if sqla_1x: + if not sqla_2: kw = {"future": future} if future else {} else: kw = {} diff --git a/alembic/util/__init__.py b/alembic/util/__init__.py index 8f684ab..3c1e27c 100644 --- a/alembic/util/__init__.py +++ b/alembic/util/__init__.py @@ -28,7 +28,6 @@ from .pyfiles import template_to_file from .sqla_compat import has_computed from .sqla_compat import sqla_13 from .sqla_compat import sqla_14 -from .sqla_compat import sqla_1x from .sqla_compat import sqla_2 diff --git a/alembic/util/sqla_compat.py b/alembic/util/sqla_compat.py index e2725d6..0070337 100644 --- a/alembic/util/sqla_compat.py +++ b/alembic/util/sqla_compat.py @@ -71,18 +71,17 @@ except ImportError: from sqlalchemy.sql.elements import _NONE_NAME as _NONE_NAME # type: ignore # noqa: E501 -if sqla_14: - # when future engine merges, this can be again based on version string - from sqlalchemy.engine import Connection as legacy_connection +class _Unsupported: + "Placeholder for unsupported SQLAlchemy classes" - sqla_1x = not hasattr(legacy_connection, "commit") -else: - sqla_1x = True try: - from sqlalchemy import Computed # noqa + from sqlalchemy import Computed except ImportError: - Computed = type(None) # type: ignore + + class Computed(_Unsupported): # type: ignore + pass + has_computed = False has_computed_reflection = False else: @@ -90,12 +89,15 @@ else: has_computed_reflection = _vers >= (1, 3, 16) try: - from sqlalchemy import Identity # noqa + from sqlalchemy import Identity except ImportError: - Identity = type(None) # type: ignore + + class Identity(_Unsupported): # type: ignore + pass + has_identity = False else: - # attributes common to Indentity and Sequence + # attributes common to Identity and Sequence _identity_options_attrs = ( "start", "increment", @@ -107,7 +109,7 @@ else: "cache", "order", ) - # attributes of Indentity + # attributes of Identity _identity_attrs = _identity_options_attrs + ("on_null",) has_identity = True diff --git a/docs/build/unreleased/1109.rst b/docs/build/unreleased/1109.rst index b6c0718..62be487 100644 --- a/docs/build/unreleased/1109.rst +++ b/docs/build/unreleased/1109.rst @@ -1,5 +1,6 @@ .. change:: :tags: usecase, commands + :tickets: 1109 Added quiet option to the command line, using the ``-q/--quiet`` option. This flag will prevent alembic from logging anything diff --git a/docs/build/unreleased/1237.rst b/docs/build/unreleased/1237.rst new file mode 100644 index 0000000..9717064 --- /dev/null +++ b/docs/build/unreleased/1237.rst @@ -0,0 +1,9 @@ +.. change:: + :tags: bug, batch + :tickets: 1237 + + Added placeholder classes for ``Computed`` and ``Identity`` when older 1.x + SQLAlchemy versions are in use, namely prior to SQLAlchemy 1.3.11 when the + ``Computed`` construct was introduced. Previously these were set to None, + however this could cause issues with certain codepaths that were using + ``isinstance()`` such as one within "batch mode". |