From: Mike Bayer Date: Sat, 26 Mar 2022 15:47:29 +0000 (-0400) Subject: adapt for column collection being "immutable" or "readonly" X-Git-Tag: rel_1_8_0~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8fc58eaa77f2118cf78ecdaca130bc298ff4143a;p=thirdparty%2Fsqlalchemy%2Falembic.git adapt for column collection being "immutable" or "readonly" in 2.0 the ColumnCollectionConstraint will use a "read only" column collection, renamed from "immutable". Add logic to detect both of these kinds of collections Change-Id: I4049c3081a2b3801ea7bfa31bb62bafb3eae4a9d --- diff --git a/alembic/util/sqla_compat.py b/alembic/util/sqla_compat.py index 0f8c12ff..9e989fd4 100644 --- a/alembic/util/sqla_compat.py +++ b/alembic/util/sqla_compat.py @@ -337,7 +337,13 @@ def _remove_column_from_collection( # same object that's present assert column.key is not None to_remove = collection[column.key] - collection.remove(to_remove) + + # SQLAlchemy 2.0 will use more ReadOnlyColumnCollection + # (renamed from ImmutableColumnCollection) + if hasattr(collection, "_immutable") or hasattr(collection, "_readonly"): + collection._parent.remove(to_remove) + else: + collection.remove(to_remove) def _textual_index_column(