From 91b4623278e6feb369287bdb4c7f0a690cff484a Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Wed, 2 Sep 2026 04:29:09 +0000 Subject: [PATCH] fix(postgres): handle localized missing prokind errors Closes #7824 --- crates/dbx-core/src/schema.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/dbx-core/src/schema.rs b/crates/dbx-core/src/schema.rs index 5797b993f5..bc28ee1a77 100644 --- a/crates/dbx-core/src/schema.rs +++ b/crates/dbx-core/src/schema.rs @@ -9420,10 +9420,19 @@ async fn postgres_object_source( fn postgres_missing_prokind_error(err: &str) -> bool { let lower = err.to_ascii_lowercase(); - lower.contains("does not exist") - && (lower.contains("column p.prokind") - || lower.contains("column \"p\".\"prokind\"") - || lower.contains("column \"prokind\"")) + let mentions_prokind = + lower.contains("p.prokind") || lower.contains("\"p\".\"prokind\"") || lower.contains("\"prokind\""); + if !mentions_prokind { + return false; + } + + // PostgreSQL localizes the undefined-column message (for example, Chinese + // servers report "字段 p.prokind 不存在"). Keep the column context so an + // unrelated relation named `prokind` cannot trigger this compatibility path. + let undefined_column = lower.contains("sqlstate 42703") + || (lower.contains("does not exist") && lower.contains("column")) + || (err.contains("不存在") && (err.contains("字段") || err.contains("列 p.prokind"))); + undefined_column } fn opengauss_sequence_cache_metadata_error(err: &str) -> bool { @@ -9705,7 +9714,11 @@ mod object_source_tests { fn detects_legacy_postgres_prokind_errors() { assert!(postgres_missing_prokind_error("ERROR: column p.prokind does not exist")); assert!(postgres_missing_prokind_error("ERROR: column \"p\".\"prokind\" does not exist")); + assert!(postgres_missing_prokind_error("错误: 字段 p.prokind 不存在\n提示: 也许您想要引用列 \"p.probin\"。")); + assert!(postgres_missing_prokind_error("ERROR: undefined column p.prokind (SQLSTATE 42703)")); assert!(!postgres_missing_prokind_error("ERROR: relation public.prokind does not exist")); + assert!(!postgres_missing_prokind_error("错误: 关系 public.prokind 不存在\n提示: 请检查列 p.probin。")); + assert!(!postgres_missing_prokind_error("ERROR: permission denied for column p.prokind")); } #[test]