Repository navigation
fix: walk WITH items of TableStatement in adapter and validator - #2928
Open
tanjiroK-coder wants to merge 1 commit into
Open
tanjiroK-coder wants to merge 1 commit into
tanjiroK-coder wants to merge 1 commit into
Conversation
SelectVisitorAdapter.visit(TableStatement) visited nothing and SelectValidator only reported tableStatement, so a data-modifying CTE in front of TABLE was invisible to StatementFeatures and to Validation: WITH d AS (DELETE FROM t RETURNING a) TABLE d gave mayModifyData() == false and passed FeaturesAllowed.SELECT. The adapter now walks the WITH items, ORDER BY and LIMIT/OFFSET/FETCH of TABLE like its VALUES visit, and SelectValidator validates the WITH list of TABLE and VALUES.
This branch has not been deployed
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.
SelectVisitorAdapter.visit(TableStatement)returns without visiting anything, andSelectValidator.visit(TableStatement)only reportsFeature.tableStatement, so theWITHlist in front of a PostgreSQLTABLEstatement never reachesStatementFeatureVisitoror anyValidationCapability.WITH d AS (DELETE FROM t RETURNING a) TABLE dtherefore comes back ascertain=[READS_DATA, RETURNS_RESULT_SET]withmayModifyData() == falseand passes the read-only guard in usage.rst, andValidationwithFeaturesAllowed.SELECTreports no error, while the same CTE in front ofSELECT a FROM dreportsMODIFIES_DATAand adelete not allowederror. PostgreSQL 18.6 runs theDELETEfor theTABLEform, also when theTABLEnames another table (WITH d AS (...) TABLE other), andTABLE t ORDER BY nextval('s')advances the sequence, which the empty adapter visit missed too. I ran into it while sending write-capable statements throughgetFeatures()and listing the ones that came back withmayModifyData() == false. The adapter now walks theWITHitems,ORDER BYandLIMIT/OFFSET/FETCHofTABLEthe way itsvisit(Values)already does, andSelectValidatorvalidates theWITHlist ofTABLEandVALUESlike it does forPlainSelect,SetOperationListandParenthesedSelect(forVALUESthis only mattered whereFeature.valuesis allowed, sinceFeaturesAllowed.SELECTrejectsVALUESitself). Pipe queries (FROM ... |>) are skipped by both visits too, but I left them alone since no server that accepts pipe syntax allows a data-modifying CTE. The newStatementFeatureVisitorTest,TableStatementValidatorTestandValuesStatementValidatorTestcases fail before and pass after, PostgreSQL validation still accepts the statement, and./gradlew check(15829 tests) andmvn verify(15811 tests) pass.