Skip to content

fix(thrift): forward server SQLSTATE on failed operations - #1083

Open
atharva18-hue wants to merge 1 commit into
databricks:mainfrom
atharva18-hue:fix/thrift-forward-sql-state-1012
Open

atharva18-hue wants to merge 1 commit into
databricks:mainfrom
atharva18-hue:fix/thrift-forward-sql-state-1012

Conversation

@atharva18-hue

Copy link
Copy Markdown

Fixes #1012

Problem

On the Thrift backend, when a statement compiles and then fails at runtime on the server, _check_command_not_in_error_or_closed_state raises ServerOperationError from the terminal operation-status payload but never forwards that payload's top-level sqlState, so the error exposes no sql_state. The kernel backend sets that exact attribute on the same exception class, so SQLSTATE availability depended on which wire protocol delivered the failure.

Change

Attach the operation-level sqlState to the raised ServerOperationError in both the displayMessage and errorMessage paths, mirroring the kernel backend's attribute forwarding. When the payload carries no SQLSTATE, sql_state is None — never invented. The envelope status.sqlState is not used.

Tests

  • Added test_get_status_forwards_server_sql_state and test_get_status_sql_state_is_none_when_server_sends_none in tests/unit/test_thrift_backend.py, mirroring the existing test_get_status_uses_display_message_if_available.
  • Verified the fix directly: calling _check_command_not_in_error_or_closed_state with an ERROR_STATE payload carrying sqlState='42000' raises ServerOperationError with sql_state == '42000' on both paths, and sql_state is None when the payload carries none.
  • pytest tests/unit/test_thrift_backend.py: 99 passed, 84 skipped. The skips are the pyarrow-gated tests (this class is skipped when pyarrow cannot import); in my environment pyarrow requires NumPy >= 2.0 while only 1.26.4 is available, so the two new tests were skipped here and need CI to run them.
  • End-to-end conformance verification (test_failed_operation_error_exposes_server_sql_state in databricks-driver-test) needs a live Databricks workspace, which I don't have.

The Thrift backend dropped the failed operation's server-reported
SQLSTATE: _check_command_not_in_error_or_closed_state raised
ServerOperationError without the payload's sqlState, while the kernel
backend sets sql_state on the same exception class. Attach the
operation-level sqlState to the raised exception in both the
displayMessage and errorMessage paths; None when the payload carries
none (never invent one).

Fixes databricks#1012

Signed-off-by: Atharva Chavhan <atharvachavhan18@gmail.com>

This branch has not been deployed

No deployments
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.

[coverage] Conformance findings: STATEMENT-028

1 participant