Skip to content

Fix Schema Diff treating a function whose input argument was renamed as two unrelated functions. #10597 - #10623

Closed
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix/issue-10597-param-rename
Closed

dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:fix/issue-10597-param-rename

Conversation

@dpage

@dpage dpage commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Schema Diff matched functions and procedures on a name that included their input argument names, so renaming an input argument produced a Source Only/Target Only pair, and the generated CREATE OR REPLACE was rejected by PostgreSQL (cannot change name of input parameter) before the old function was dropped.

  • Functions and procedures are now matched on their name and input argument types (oidvectortypes(proargtypes)), which is how PostgreSQL identifies them.
  • Titles are unchanged: they still show argument names, taken from the source for a Different object. directory_compare gains a small, generic way for a node to supply a display title separate from its match key; the title is never compared.
  • When the input argument names differ, the target is dropped and recreated from the source, as Fix Schema Diff treating functions that differ only in OUT arguments or return type as unrelated objects. #6652 #10595 already does for OUT arguments and return types.

The EPAS templates got the same change but are untested locally.

Test plan

  • Extended tools.schema_diff.tests.test_schema_diff_function_signature with renamed IN and INOUT arguments, an unnamed-to-named argument and a renamed procedure argument; it checks the title, the DROP before CREATE, and that the target compares as Identical after the script is applied
  • tools.schema_diff package (9 tests) and the functions node package (78 tests) on PostgreSQL 18
  • pycodestyle on the changed files

Closes #10597

Summary by CodeRabbit

  • Bug Fixes
    • Schema Diff now detects changed input-argument names in functions and procedures and generates SQL to drop and recreate objects when required.
    • Function and procedure comparisons now match objects by their input argument types, even when argument names differ.
    • Schema Diff displays object titles consistently, using the source-side signature for changed objects.

…as two unrelated functions. pgadmin-org#10597

Schema Diff matched functions and procedures on a name that included their
input argument names, so renaming an input argument produced a Source
Only/Target Only pair, and the generated CREATE OR REPLACE was rejected
by PostgreSQL before the old function was dropped.

Functions and procedures are now matched on their name and input argument
types, as PostgreSQL identifies them, whilst still being shown under their
name with argument names (the source's, for a Different object). When the
input argument names differ, the target is dropped and recreated from the
source.

Closes pgadmin-org#10597
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: pgadmin-org/pgadmin4/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3556f51b-f567-404c-acef-bf058d14e692
📥 Commits

Reviewing files that changed from the base of the PR and between b98470f and 140108a.

📒 Files selected for processing: 7
  • web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
  • web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/functions/pg/sql/default/node.sql
  • web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/functions/ppas/sql/default/node.sql
  • web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedures/pg/sql/default/node.sql
  • web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedures/ppas/sql/default/node.sql
  • web/pgadmin/tools/schema_diff/directory_compare.py
  • web/pgadmin/tools/schema_diff/tests/test_schema_diff_function_signature.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

Walkthrough

Schema Diff now matches functions and procedures by name and input argument types, while displaying titles that include input argument names and exclude OUT arguments. When input argument names differ, it reports a single different object and generates SQL that drops and recreates the target.

Changes

Function and procedure signature matching

Layer / File(s) Summary
Signature keys and display names
web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/functions/*/sql/default/node.sql, web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedures/*/sql/default/node.sql
The function and procedure queries return a diff_key based on the object name and input argument types. The display name remains separate and includes input argument names while excluding OUT arguments.
Comparison titles and recreation behavior
web/pgadmin/tools/schema_diff/directory_compare.py, web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
Directory comparison uses schema-diff titles for results without treating titles as compared properties. Function comparison records input argument names and treats their differences as a reason to drop and recreate the target.
Signature behavior tests
web/pgadmin/tools/schema_diff/tests/test_schema_diff_function_signature.py
Tests cover renamed function and procedure arguments, displayed source-side titles, and expected drop-and-recreate scripts.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant FunctionQueries
  participant DirectoryCompare
  participant FunctionComparison
  participant SchemaDiffSQL
  FunctionQueries->>DirectoryCompare: Return name and diff_key
  DirectoryCompare->>FunctionComparison: Compare objects matched by diff_key
  FunctionComparison->>SchemaDiffSQL: Drop and recreate when input argument names differ
Loading
Merge Risk: 🔵 Low · up to 14010

Schema Diff now matches functions by name and input argument types. The change appears sound, but the EPAS template variants were not tested locally, so a quick check on EPAS is advisable.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: Schema Diff now matches functions correctly when an input argument is renamed.
Linked Issues check Passed Issue #10597 requires matching functions and procedures by name plus input argument types, reporting renamed input arguments as one Different object, and dropping the target before recreation when Pos…
Out of Scope Changes check Passed The changes stay within issue #10597. The PostgreSQL and EPAS templates implement the required matching key. The directory_compare title support enables the required display behavior. The function-n…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 3 files. (4 skipped: 4…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dpage

dpage commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

Squashed and merged as 6594977.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema Diff treats a function whose input parameter was renamed as two unrelated functions

1 participant