fix(postgres): 存储过程含 DEFAULT 参数时查看 DDL 报 Object source not found - #8281
Merged
Conversation
Servers without pg_get_function_identity_arguments (e.g. TBase) build the object list signature with pg_get_function_arguments instead, which includes DEFAULT clauses. Fetching the DDL always matched with pg_get_function_identity_arguments (no DEFAULT clauses), so routines with default-valued parameters always failed with "Object source not found". Add a narrow fallback that retries with the legacy formatter when that exact error occurs for a Function/Procedure with a signature. Fixes t8y2#8279 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LKS8RLQjueXCwVJov2zWD3
Contributor
Author
复现证据(终端输出,本 bug 为后端 API 逻辑问题,无法通过截图直接验证)BEFORE(未修复, AFTER(应用本次修复) 两次请求针对的是共享测试 PostgreSQL 16.14 上真实创建的存储过程, 回归验证(AFTER,同一后端):不带 |
Owner
|
Thanks for the contribution! Merged in 93a4b58, will be released in the next version. |
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.
问题
在探测不到
pg_get_function_identity_arguments(真实发生在腾讯 TBase 10.23 等兼容分支)的 PostgreSQL 兼容服务器上,对象列表查询会退回用pg_get_function_arguments生成签名——该函数会包含参数的DEFAULT ...子句。而查看存储过程/函数 DDL 时无条件用pg_get_function_identity_arguments做签名匹配——该函数不包含DEFAULT子句。只要routine 带默认参数,两侧签名格式永远对不上,查询返回 0 行,报错Object source not found。修复
新增
postgres_function_object_source_sql_with_legacy_signature(),构造与对象列表 legacy 兼容模式一致(pg_get_function_arguments)的签名过滤条件;在postgres_object_source()中新增一条窄范围 fallback:仅当非 openGauss 家族、类型为 Function/Procedure、带 signature、且主查询恰好报"Object source not found"时,用该 legacy 签名查询重试一次。不影响 View/Sequence/Trigger、不影响 openGauss 已有 fallback 链、不影响任何现有成功路径。复现与验证
共享测试环境是原生 PostgreSQL(探测器返回真,走不到 legacy 分支),本机也没有可用的 TBase 实例,因此复现分两步、均为真实数据库 + 真实运行的应用:
DEFAULT参数的存储过程,验证pg_get_function_arguments(含DEFAULT 0)与pg_get_function_identity_arguments(不含)确实不同——根因坐实。cargo run -p dbx-web后端 + 真实网络请求,手工传入该库里真实存在的 legacy 格式签名值(模拟探针失败后前端本应传入的值):GET /api/schema/object-source?...&signature=IN i_id numeric, IN i_page numeric DEFAULT 0→HTTP 500 {"detail":"Object source not found"},与 issue 描述完全一致。HTTP 200,正确返回CREATE OR REPLACE PROCEDURE ...DDL。cargo test -p dbx-core --lib schema:::184/184 通过(含新增 1 条针对 legacy 签名 SQL 构造的单测)。cargo clippy -p dbx-core --lib -- -D warnings:干净。cargo fmt --check -p dbx-core:改动文件无格式问题。Fixes #8279
🤖 Generated with Claude Code