Skip to content

Fix swapped names in PostgreSQL undefined column error message#39125

Open
thswlsqls wants to merge 1 commit into
apache:masterfrom
thswlsqls:39123
Open

Fix swapped names in PostgreSQL undefined column error message#39125
thswlsqls wants to merge 1 commit into
apache:masterfrom
thswlsqls:39123

Conversation

@thswlsqls

Copy link
Copy Markdown
Contributor

Fixes #39123.

Changes proposed in this pull request:

  • Swap the two arguments passed to PostgreSQLVendorError.UNDEFINED_COLUMN in PostgreSQLDialectExceptionMapper.convert() so the reason format Column "%s" of table "%s" does not exist receives the column name first and the table name second. A missing column user_id in table t_order now produces Column "user_id" of table "t_order" does not exist instead of the reversed message.
  • Aligns this branch with sibling branches in the same mapper (PRIVILEGE_NOT_GRANTED, INVALID_PARAMETER_VALUE, PROTOCOL_VIOLATION) that already match field order to format order.
  • Add assertConvertColumnNotFoundMessage asserting the formatted message body; the existing assertConvert only checked sqlState and severity, so it missed the swap.

Before committing this PR, I'm sure that I have checked the following options:

  • My code follows the code of conduct of this project.
  • I have self-reviewed the commit code.
  • I have (or in comment I request) added corresponding labels for the pull request.
  • I have passed maven check locally : ./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e.
  • I have made corresponding changes to the documentation.
  • I have added corresponding unit tests for my changes.
  • I have updated the Release Notes of the current development version. For more details, see Update Release Note

@terrymanu terrymanu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Review Result: Not Mergeable

Feedback Mode: Needs Discussion

Reason: The patch correctly reorders arguments for the dialect exception in isolation, but that exception is not produced by the PostgreSQL SELECT binding path described in #39123. The linked issue’s root-cause model and the implementation scope need to be reconciled before this can close the reported bug.

Issues

P1: The changed mapper is not on the reported SELECT failure path

  • Problem: #39123 reports selecting a nonexistent column. However, the relevant dialect ColumnNotFoundException is constructed by PostgreSQL only inside the prepared-statement INSERT Describe branch at PostgreSQLComDescribeExecutor.java:106. A normal projected column is bound through ColumnProjectionSegmentBinder.java:46, where ColumnSegmentBinder.java:216 throws the separate infra ColumnNotFoundException. That exception extends ShardingSphereSQLException and is converted before the dialect-mapper branch at SQLExceptionTransformEngine.java:49. The new test at PostgreSQLDialectExceptionMapperTest.java:83 mocks the mapper input directly, so it does not establish the reported Proxy path.
  • Impact: Merging with Fixes #39123 could close the reported SELECT bug while only changing the extended-protocol INSERT Describe behavior.
  • Discussion Needed: Please pause the current implementation direction and confirm the exact SQL and protocol phase that reproduces #39123. If it is a SELECT, the discussion should identify the binder/error-transformation owner. If it is actually an INSERT Describe failure, the issue and PR scope should first be narrowed accordingly. The type: discussion label is appropriate until this path is agreed.

Review Details

  • Review Focus: Code Correctness Review — CI not reviewed by request.
  • Reviewed Scope: All three changed files: RELEASE-NOTES.md, PostgreSQLDialectExceptionMapper.java, and PostgreSQLDialectExceptionMapperTest.java; supporting exception definitions, production construction sites, PostgreSQL Describe handling, column binding, and exception transformation were traced. Latest head: 0eddd07cef46ead1ee6bbab3f34107e13ee32221; base: master at 7568693e8ee02637a47d3cca8acbf449797932e5; local merge-base: 6778bfbe08c1ff59574874575a6ab4b932066dba. The local triple-dot file list matched GitHub’s /pulls/39125/files list.
  • Not Reviewed Scope: GitHub Actions/CI and live Proxy/client reproduction were not reviewed. Unrelated modules were inspected only where necessary to trace the exception path.
  • Verification: GitHub PR, file, commit, issue, comment, and review evidence was accessible. The bounded review inventory, merge-base comparison, exact-head source inspection, and repository-wide usage searches completed successfully. Maven was not run because the active checkout was not the PR head; no stale local test result was used. This does not affect the blocker because the path mismatch is established directly from the latest-head production call graph.
  • Release Note / User Docs: A release-note entry is present, but its applicability depends on the resolved issue scope. Separate user documentation is not required because no configuration, API, migration, or compatibility contract changes.

@thswlsqls

Copy link
Copy Markdown
Contributor Author

Agreed on the mechanics: the mapper only sees the dialect ColumnNotFoundException (database.exception.core…), which for PostgreSQL is constructed solely in PostgreSQLComDescribeExecutor's INSERT Describe branch. A projected SELECT column throws the infra ColumnNotFoundException via ColumnSegmentBinder, and SQLExceptionTransformEngine routes that through its ShardingSphereSQLException branch before the dialect-mapper branch, so it never hits this mapper.

That said, the swapped Column "x" of table "y" does not exist text is uniquely PostgreSQLVendorError.UNDEFINED_COLUMN from this mapper — the infra path emits Unknown column '…' in '…' instead. So #39123's symptom, if it shows that swapped wording, must traverse the extended-protocol Describe (INSERT) phase, and the patch fixes it there. I'll confirm the exact SQL/phase with the reporter and correct the "SELECT" wording. If a plain SELECT is also expected to surface this, that's a separate change in ColumnSegmentBinder, out of scope here.

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.

PostgreSQL undefined column error swaps column and table names

2 participants