]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
adapt for column collection being "immutable" or "readonly"
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 26 Mar 2022 15:47:29 +0000 (11:47 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 26 Mar 2022 15:47:29 +0000 (11:47 -0400)
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

alembic/util/sqla_compat.py

index 0f8c12ff7b5f7dbb0bac43c3a32dd7a6a69d7080..9e989fd4ad87e663a231f502995c10631972c4de 100644 (file)
@@ -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(