Reflection: Report column nullability, and filter views by schema - #315
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_columns reads information_schema.columns.is_nullable instead of reporting every column, primary keys included, as nullable. - get_view_names filters by the requested schema; the schema was passed as a parameter the query never used, so views of all schemas came back. - has_table reports views as well as tables, matching SQLAlchemy 2.0's Inspector.has_table, and get_view_definition is implemented. - Reflection honours the schema URL parameter that get_table_names already uses, instead of falling back to doc.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
CrateDB up to 6.0 reports information_schema.columns.is_nullable as a
BOOLEAN; later versions report 'YES'/'NO', and bool('NO') is True, so
primary key and NOT NULL columns reflected as nullable. Accept both.
Give the mocked get_columns cursor a three-column description and use
crate:///?schema=sales, so the tests also pass on SQLAlchemy 1.3/1.4.
Add a live reflection test.
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.
Problem
Several reflection methods return wrong results against a live CrateDB (verified on 5.10.16 with SQLAlchemy 2.0.52):
get_columnshard-codesnullable=True, so a primary key orNOT NULLcolumn reflects as nullable.information_schema.columns.is_nullablereports the real value.get_view_namespasses the schema as a parameter, but the query has no placeholder for it, so views of every schema are returned for any schema.has_tableonly checks base tables. SQLAlchemy 2.0'sInspector.has_tablealso reports views.get_view_definitionis not implemented (NotImplementedError), althoughinformation_schema.views.view_definitionexists.crate://host/?schema=sales,get_table_names()lists tables fromsales, butget_columns,get_pk_constraintandget_view_namesquerydoc. A listed table then reflects no columns and no primary key.Change
get_columnsselectsis_nullable(ordered byordinal_position) and returns it asnullable. CrateDB up to 6.0 reportsis_nullableas aBOOLEAN, while 6.4 and later report'YES'/'NO'text (wherebool('NO')would beTrue), so both forms are accepted.get_view_namesfilters ontable_schema = ?.get_view_definitionreadsinformation_schema.views.has_tablemakes one query againstinformation_schema.tableswithtable_type IN ('BASE TABLE', 'VIEW'). CrateDB lists views there too, so the bulk tests' call counts stay the same._reflection_schemahelper resolves the schema in this order: the explicit argument, then the URLschemaparameter, then the default. The reflection methods above use it.Tests
'YES'/'NO'forms), view listing and definition,has_tableon a view, and URL-schema resolution forget_columns,get_pk_constraintandget_view_names.test_get_view_namesandtest_has_tablenow expect the new SQL. The mockedget_columnscursor describes all three selected columns, and the URL-schema tests usecrate:///?schema=sales, so they also pass on SQLAlchemy 1.3 and 1.4.tests/reflection_test.py: a live test (testcontainers) that a primary key and aNOT NULLcolumn reflect as not nullable.poe lintis clean andintegration.pypasses. pytest gives 209 passed on SQLAlchemy 2.1.1, 195 passed on 1.4.54, and 132 passed on 1.3.24. On 1.3 there is one failure,test_schema.py::test_correct_schema, which fails the same way onmain.has_tableon a view, the view definition, and URL-schema column/PK reflection.