Exclude views from get_table_names() - #310
Open
aminghadersohi wants to merge 2 commits into
Open
aminghadersohi wants to merge 2 commits into
aminghadersohi wants to merge 2 commits into
Conversation
get_table_names() read every row of information_schema.tables for the schema, so views were returned as tables as well as by get_view_names(). SQLAlchemy defines get_table_names() as base tables only, and callers that list tables and views separately showed each view twice. Filter on table_type = 'BASE TABLE'. has_table() previously relied on get_table_names(); it now checks all relations directly, so it keeps returning True for views as SQLAlchemy 2.0 specifies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
get_table_names()selects every row ofinformation_schema.tablesfor the schema, so views are returned as tables in addition to being returned byget_view_names(). SQLAlchemy definesget_table_names()as base tables only; applications that list tables and views separately show each view twice.This filters on
table_type = 'BASE TABLE'.has_table()previously delegated toget_table_names(); it now checks all relations directly, so it still returnsTruefor views, as SQLAlchemy 2.0 specifies. The pre-v2SHOW TABLESbranch is unchanged. ACHANGES.mdentry is added under the unreleased 2.0.5 section.Tests (
test/test_introspection.py::TableNamesTest), against CockroachDB v24.3.0 single node:test_get_table_names_excludes_viewsfails (assert 'names_view' not in ['names_base', 'names_view']); 1 failed, 17 passedThe
test_suite_sqlalchemy.pyreflection subset (-k "table_names or has_table or view_names or get_multi") has an identical set of 9 pre-existing failures (test_get_multi_foreign_keysvariants and onetest_get_table_names[...foreign_key...]) with and without this change; 123 pass in both.