fix(plpgsql-deparser): fix failing fixtures - EXCEPTION blocks, schema qualification, implicit variables #269
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.
fix(plpgsql-deparser): fix EXCEPTION blocks, schema qualification, implicit variables
Summary
This PR fixes 13 of the 16 known failing fixtures in the plpgsql-deparser round-trip test suite. The main fixes are:
EXCEPTION block handling: The deparser was not outputting EXCEPTION blocks because it checked for
block.exceptions.exc_listdirectly, but the parser wraps exception blocks in aPLpgSQL_exception_blockwrapper. Now handles both formats.Schema qualification preservation: Modified
deparseType()to preserve schema qualification for%rowtypeand%typereferences (e.g.,pg_catalog.pg_class%rowtype[]no longer gets incorrectly stripped).Implicit variables filtering: Added
sqlstateandsqlerrmto the list of implicit variables filtered from DECLARE sections (PostgreSQL adds these automatically for exception handling).Test utils improvement: Added
varnoto the list of properties ignored during AST comparison, since variable numbers change when implicit variables are filtered out.Results: 187 of 190 fixtures now pass (up from 174). Only 3 fixtures remain failing:
plpgsql_varprops-13.sql(nested DECLARE inside FOR loop)plpgsql_transaction-17.sql(CURSOR FOR loop with EXCEPTION block)plpgsql_control-15.sql(labeled block with EXIT statement)Review & Testing Checklist for Human
WHEN ... THENclauses and their actions are semantically correct.typname.includes('%rowtype')- verify this doesn't have false positives/negatives for unusual type names.varnovalues during comparison. Confirm this is safe and doesn't hide semantic differences.Notes
as anytype cast on line 582 and 588 ofplpgsql-deparser.tsis used to handle the wrapped exception block format - this could be improved with proper typing.Link to Devin run: https://app.devin.ai/sessions/8e1c971e9b194cd9a7dda034c89bd74b
Requested by: @pyramation