Skip to content

Commit 6526ded

Browse files
CaselITGerrit Code Review
authored andcommitted
Merge "adapt alembic for the inherit_schema change sqlalchemy 2.1" into main
2 parents c34ca7f + f2b605a commit 6526ded

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

alembic/util/sqla_compat.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def _safe_int(value: str) -> Union[int, str]:
7070
sqla_14_18 = _vers >= (1, 4, 18)
7171
sqla_14_26 = _vers >= (1, 4, 26)
7272
sqla_2 = _vers >= (2,)
73+
sqla_2_1 = _vers >= (2, 1)
7374
sqlalchemy_version = __version__
7475

7576
if TYPE_CHECKING:
@@ -493,3 +494,9 @@ def is_expression(expr: Any) -> bool:
493494
if not isinstance(expr, ColumnClause) or expr.is_literal:
494495
return True
495496
return False
497+
498+
499+
def _inherit_schema_deprecated() -> bool:
500+
# at some point in 2.1 inherit_schema was replaced with a property
501+
# so that's preset at the class level, while before it wasn't.
502+
return sqla_2_1 and hasattr(sqltypes.Enum, "inherit_schema")

tests/test_autogen_render.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,10 @@ def test_render_modify_nullable_w_default(self):
17631763
)
17641764

17651765
def _check_enum_inherit_schema(self, enum):
1766-
if enum.inherit_schema:
1766+
if (
1767+
not sqla_compat._inherit_schema_deprecated()
1768+
and enum.inherit_schema
1769+
):
17671770
return enum, ", inherit_schema=True"
17681771
else:
17691772
return enum, ""

0 commit comments

Comments
 (0)