From: Federico Caselli Date: Thu, 4 Jun 2026 21:23:46 +0000 (+0200) Subject: remove legacy include_columns in index reflection X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=7543c167eb9b234afabee455702002db2a54a72f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git remove legacy include_columns in index reflection Removed the legacy ``include_columns`` key from the dictionary returned by the index reflection methods of some dialects. This information is now part of the ``dialect_options`` dictionary under the key ``{dialect_name}_include``, such as ``postgresql_include`` or ``mssql_include``. Fixes: #13350 Change-Id: I9535690350d97e19477f7e9919dc4994b876af47 --- diff --git a/doc/build/changelog/unreleased_21/13350.rst b/doc/build/changelog/unreleased_21/13350.rst new file mode 100644 index 0000000000..2959fe2f4d --- /dev/null +++ b/doc/build/changelog/unreleased_21/13350.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: reflection + :tickets: 13350 + + Removed the legacy ``include_columns`` key from the dictionary returned + by the index reflection methods of some dialects. + This information is now part of the ``dialect_options`` dictionary under the key + ``{dialect_name}_include``, such as ``postgresql_include`` or ``mssql_include``. diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index fce6e084d3..a818ccd20b 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -4597,10 +4597,7 @@ index_info AS ( "name": row["name"], "unique": row["is_unique"] == 1, "column_names": [], - # NOTE: this is legacy, this is part of - # dialect_options now as of #7382 - "include_columns": [], - "dialect_options": {}, + "dialect_options": {"mssql_include": []}, } do = current["dialect_options"] index_type = row["type"] @@ -4635,23 +4632,20 @@ index_info AS ( if idx_id not in indexes_by_table[tname]: continue index_def = indexes_by_table[tname][idx_id] - is_colstore = index_def["dialect_options"].get("mssql_columnstore") - is_clustered = index_def["dialect_options"].get("mssql_clustered") + do = index_def["dialect_options"] + is_colstore = do.get("mssql_columnstore") + is_clustered = do.get("mssql_clustered") if not (is_colstore and is_clustered): # a clustered columnstore index includes all columns but does # not want them in the index definition if row["is_included_column"] and not is_colstore: # a noncludsted columnstore index reports that includes # columns but requires that are listed as normal columns - index_def["include_columns"].append(row["name"]) + do["mssql_include"].append(row["name"]) else: index_def["column_names"].append(row["name"]) for tname, idx_dict in indexes_by_table.items(): - for index_info in idx_dict.values(): - index_info["dialect_options"]["mssql_include"] = index_info[ - "include_columns" - ] result[(schema, tname)] = list(idx_dict.values()) for n in names: diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 97a553bec1..12d5c60e07 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -5325,9 +5325,6 @@ class PGDialect(default.DefaultDialect): "filter_definition" ] if self.server_version_info >= (11,): - # NOTE: this is legacy, this is part of - # dialect_options now as of #7382 - index["include_columns"] = inc_cols dialect_options["postgresql_include"] = inc_cols if row["indnullsnotdistinct"]: # the default is False, so ignore it. diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py index 4374622c5a..3cb271c7bd 100644 --- a/lib/sqlalchemy/testing/suite/test_reflection.py +++ b/lib/sqlalchemy/testing/suite/test_reflection.py @@ -1281,7 +1281,6 @@ class ComponentReflectionTest(ComparesTables, OneConnectionTablesTest): "column_names": list(cols), "name": name, "dialect_options": mock.ANY, - "include_columns": [], } if column_sorting: res["column_sorting"] = column_sorting @@ -2079,8 +2078,6 @@ class ComponentReflectionTest(ComparesTables, OneConnectionTablesTest): expected = [ {"unique": False, "column_names": ["foo"], "name": "user_tmp_ix"} ] - if testing.requires.index_reflects_included_columns.enabled: - expected[0]["include_columns"] = [] eq_( [idx for idx in indexes if idx["name"] == "user_tmp_ix"], expected, @@ -2914,7 +2911,6 @@ class ComponentReflectionTestExtra(ComparesIndexes, fixtures.TestBase): def completeIndex(entry): if testing.requires.index_reflects_included_columns.enabled: - entry["include_columns"] = [] entry["dialect_options"] = { f"{connection.engine.name}_include": [] } @@ -2997,7 +2993,6 @@ class ComponentReflectionTestExtra(ComparesIndexes, fixtures.TestBase): { "name": "t_idx", "column_names": ["x"], - "include_columns": ["y"], "unique": False, "dialect_options": mock.ANY, } diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index fa1fb457db..f3af3e1f91 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -193,7 +193,6 @@ class PartitionedReflectionTest(fixtures.TablesTest, AssertsExecutionResults): "name": "my_index", "unique": False, "column_names": ["q"], - "include_columns": [], "dialect_options": {"postgresql_include": []}, } ], @@ -209,7 +208,6 @@ class PartitionedReflectionTest(fixtures.TablesTest, AssertsExecutionResults): [ { "column_names": ["q"], - "include_columns": [], "dialect_options": {"postgresql_include": []}, "name": mock.ANY, "unique": False, @@ -386,7 +384,6 @@ class MaterializedViewReflectionTest( "column_sorting": {"data": ("desc",)}, } if connection.dialect.server_version_info >= (11, 0): - exp["include_columns"] = [] exp["dialect_options"] = {"postgresql_include": []} plain = {(None, "test_regview"): []} mat = {(None, "test_mview"): [exp]} @@ -1751,14 +1748,12 @@ class ReflectionTest( "(other::text || id::text)", ], "unique": False, - "include_columns": [], "dialect_options": {"postgresql_include": []}, }, { "name": "idx2", "column_names": ["id"], "unique": True, - "include_columns": [], "dialect_options": { "postgresql_include": [], "postgresql_where": "((name)::text = 'test'::text)", @@ -1773,7 +1768,6 @@ class ReflectionTest( "lower(aname::text)", ], "unique": False, - "include_columns": [], "dialect_options": {"postgresql_include": []}, "column_sorting": {"lower(aname::text)": ("desc",)}, }, @@ -1782,7 +1776,6 @@ class ReflectionTest( "column_names": ["name", None, "aname"], "expressions": ["name", "lower(other::text)", "aname"], "unique": False, - "include_columns": [], "dialect_options": { "postgresql_include": [], "postgresql_where": "((name)::text <> 'foo'::text)", @@ -1796,7 +1789,6 @@ class ReflectionTest( "name": "ix_party_name", "column_names": ["name"], "unique": False, - "include_columns": [], "dialect_options": {"postgresql_include": []}, }, ] @@ -1807,7 +1799,6 @@ class ReflectionTest( "column_names": ["name", None], "expressions": ["name", "upper(other::text)"], "unique": True, - "include_columns": [], "dialect_options": { "postgresql_include": [], "postgresql_nulls_not_distinct": True, @@ -1818,7 +1809,6 @@ class ReflectionTest( if version < (11,): for index in expected: - index.pop("include_columns") index["dialect_options"].pop("postgresql_include") if not index["dialect_options"]: index.pop("dialect_options") @@ -1958,7 +1948,6 @@ class ReflectionTest( ind = connection.dialect.get_indexes(connection, "t", None) expected = [{"name": "idx1", "unique": False, "column_names": ["y"]}] if testing.requires.index_reflects_included_columns.enabled: - expected[0]["include_columns"] = [] expected[0]["dialect_options"] = {"postgresql_include": []} eq_(ind, expected) @@ -1991,7 +1980,6 @@ class ReflectionTest( } ] if testing.requires.index_reflects_included_columns.enabled: - expected[0]["include_columns"] = [] expected[0]["dialect_options"]["postgresql_include"] = [] eq_(ind, expected) @@ -2024,7 +2012,6 @@ class ReflectionTest( } ] if testing.requires.index_reflects_included_columns.enabled: - expected[0]["include_columns"] = [] expected[0]["dialect_options"]["postgresql_include"] = [] eq_(ind, expected) m = MetaData() @@ -2070,7 +2057,6 @@ class ReflectionTest( } ] if connection.dialect.server_version_info >= (11, 0): - expected[0]["include_columns"] = [] expected[0]["dialect_options"]["postgresql_include"] = [] eq_(ind, expected) @@ -2109,7 +2095,6 @@ class ReflectionTest( "postgresql_nulls_not_distinct": True, "postgresql_include": [], }, - "include_columns": [], }, { "unique": True, @@ -2119,7 +2104,6 @@ class ReflectionTest( "postgresql_nulls_not_distinct": True, "postgresql_include": [], }, - "include_columns": [], "duplicates_constraint": "unq1", }, ] @@ -2181,7 +2165,6 @@ class ReflectionTest( { "unique": False, "column_names": ["x"], - "include_columns": ["name"], "dialect_options": {"postgresql_include": ["name"]}, "name": "idx1", }, @@ -2190,7 +2173,6 @@ class ReflectionTest( "column_names": [None, None], "expressions": ["lower(other)", "(id * id)"], "unique": True, - "include_columns": ["id"], "dialect_options": {"postgresql_include": ["id"]}, }, { @@ -2202,7 +2184,6 @@ class ReflectionTest( "lower(aname::text)", ], "unique": False, - "include_columns": ["id", "x"], "dialect_options": {"postgresql_include": ["id", "x"]}, "column_sorting": { "other": ("desc", "nulls_last"), @@ -2612,7 +2593,6 @@ class ReflectionTest( } ] if testing.requires.index_reflects_included_columns.enabled: - expected[0]["include_columns"] = [] expected[0]["dialect_options"]["postgresql_include"] = [] eq_(insp.get_indexes("t"), expected)