Skip to content

[SPARK-59119][4.4][CONNECT][PYTHON] Do not crash on cyclic or out-of-range cause_idx in error details - #60860

Open
holdenk wants to merge 2 commits into
apache:branch-4.4from
holdenk:backport-pr58515-branch-4.4
Open

holdenk wants to merge 2 commits into
apache:branch-4.4from
holdenk:backport-pr58515-branch-4.4

Conversation

@holdenk

@holdenk holdenk commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Backport of #58515 to branch-4.4, cherry-picked from 581c83b.

Opened by dev/merge_spark_pr.py. Merging this PR with the script commits its first commit's message, which keeps #58515's message, footer and author, and adds Backport-PR with this PR's number and the merger's sign-off. Fixups go in as further commits; their authors get Co-authored-by.

… cause_idx in error details

### What changes were proposed in this pull request?

`_extract_jvm_stacktrace` in `pyspark/errors/exceptions/connect.py` follows the `cause_idx` chain from `FetchErrorDetailsResponse` recursively, without validating the index. This PR walks the chain iteratively instead and stops when the next index is out of range or has already been visited, so each error is formatted at most once.

The Scala client has a similar unguarded recursion in `GrpcExceptionConverter.errorsToThrowable`; this PR only covers the Python client.

### Why are the changes needed?

If the error details returned by `FetchErrorDetails` contain a malformed cause chain, the client crashes inside error conversion and the original server error is lost:

- a cyclic `cause_idx` (two errors pointing at each other, or an error listed as its own cause) raises `RecursionError: maximum recursion depth exceeded`
- an out-of-range `cause_idx` raises `IndexError: list index out of range`

Reproducible by calling `convert_exception` with a `FetchErrorDetailsResponse` where `errors[0].cause_idx = 1` and `errors[1].cause_idx = 0`.

### Does this PR introduce _any_ user-facing change?

Only for malformed error details: the client now raises the converted server exception instead of `RecursionError`/`IndexError`. Well-formed cause chains are formatted exactly as before.

### How was this patch tested?

Added `test_convert_exception_with_malformed_cause_chain` to `pyspark.errors.tests.test_connect_errors_conversion` covering the mutual cycle, the self-cycle, and the out-of-range case. All tests in the module pass:

```
python -m pytest python/pyspark/errors/tests/test_connect_errors_conversion.py
13 passed
```

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code

Closes apache#58515 from Eliaaazzz/SPARK-59119.

Authored-by: Elia Liu <Elialiu760317@outlook.com>
Signed-off-by: Holden Karau <holden.karau@snowflake.com>
(cherry picked from commit 581c83b)
Signed-off-by: Holden Karau <holden.karau@snowflake.com>
@holdenk
holdenk force-pushed the backport-pr58515-branch-4.4 branch from c4dabae to 474d636 Compare November 25, 2026 05:12
…rmExpressionSuite

Add IntBucketFunction and ProduceResultBucketFunction to
TransformExpressionSuite. The SPARK-62319 backport uses them, but they come
from SPARK-60541, which is not on branch-4.4, so catalyst test compilation
fails.

Co-authored-by: Isaac <no-reply@databricks.com>
(cherry picked from commit b112919)

NOTE: TEMPORARY cherry-pick of apache#60865 (not part
of this backport) so CI can compile TransformExpressionSuite on this branch. Once
that fix is merged into the release branch this commit drops out on rebase; do not
merge it as part of this PR.
@github-actions github-actions Bot added the SQL label Nov 25, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants