Schema Diff: stop injecting whitespace into applied function/procedure bodies - #10317
Schema Diff: stop injecting whitespace into applied function/procedure bodies#10317dpage wants to merge 1 commit into
Conversation
…edure bodies (pgadmin-org#10302) Generating a script for a function or procedure that only exists on the source ("Source Only") routed through FunctionView.sql(), which always calls reformat_prosrc_code() to wrap the body with a leading and trailing newline around $BODY$...$BODY$ purely for readability in the SQL panel. That reformatted body was then executed verbatim against the target, so PostgreSQL stored the extra newlines in prosrc: the target's body no longer matched the source's byte for byte, and re-comparing kept reporting a whitespace-only difference unless "Ignore whitespace" was ticked. Schema Diff's update path (CREATE OR REPLACE against an existing target object) already suppressed this formatting via allow_code_formatting, added for pgadmin-org#7102; this extends the same guard to the create/"Source Only" path so Schema Diff never adds whitespace of its own to the SQL it actually applies. Added a dedicated regression test covering both the "Source Only" and "Different" cases for a function and a procedure: applying the generated script now leaves every object comparing as Identical without needing "Ignore whitespace".
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 2 remain after this review. WalkthroughSchema Diff SQL generation now accepts an ChangesSchema Diff body formatting
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to This localized change prevents formatting-only differences when applying function and procedure definitions, with dedicated regression coverage. No actionable merge-blocking risk remains beyond normal checks and review. Sequence Diagram(s)sequenceDiagram
participant SchemaDiffTest
participant SchemaDiff
participant FunctionSQLGenerator
participant TargetDatabase
SchemaDiffTest->>SchemaDiff: generate routine diff SQL
SchemaDiff->>FunctionSQLGenerator: disable code formatting
FunctionSQLGenerator-->>SchemaDiff: return SQL with stored body whitespace
SchemaDiff->>TargetDatabase: apply generated DDL
SchemaDiffTest->>SchemaDiff: compare source and target routines
SchemaDiff-->>SchemaDiffTest: report identical without ignored whitespace
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
What this is
Applying a Schema Diff script that creates a function or procedure that only exists on the source ("Source Only") left a whitespace-only difference behind, so re-comparing the two databases kept reporting the object as different unless "Ignore whitespace" was ticked.
The "Source Only" path routed through
FunctionView.sql(), which always callsreformat_prosrc_code()to wrap the body with a leading and trailing newline around$BODY$...$BODY$purely for readability in the SQL panel. That reformatted body was then executed verbatim against the target, so PostgreSQL stored the extra newlines inprosrc: the target's body no longer matched the source's byte for byte.Schema Diff's update path (
CREATE OR REPLACEagainst an existing target object) already suppressed this formatting via anallow_code_formattingflag, added for #7102, but that flag was never threaded through the create/"Source Only" path.The fix
Extends the existing
allow_code_formattingguard tosql()itself, and passesallow_code_formatting=Falsefrom theget_sql_from_diff()branch that builds the DDL actually applied to the target.Testing
Added a dedicated regression test covering both the "Source Only" and "Different" cases for a function and a procedure: applying the generated script now leaves every object comparing as Identical without needing "Ignore whitespace".
tools.schema_diffpasses against PostgreSQL 18;pycodestyleis clean.Fixes #10302.
Summary by CodeRabbit
Bug Fixes
Tests