Skip to content

Commit 2e918e8

Browse files
committed
[SPARK-46532][CONNECT][PYTHON][FOLLOW-UP] Pass message parameters in Python Spark Connect client
### What changes were proposed in this pull request? This PR is a followup of #44468 that addresses the additional metadata in Python Spark Connect client. ### Why are the changes needed? For feature parity. ### Does this PR introduce _any_ user-facing change? Yes, when `spark.sql.connect.enrichError.enabled` is disabled, users are sill able to get the message parameters. ### How was this patch tested? Unittest was added. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #44528 from HyukjinKwon/SPARK-46532-followup. Authored-by: Hyukjin Kwon <gurwls223@apache.org> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
1 parent f99b86a commit 2e918e8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

python/pyspark/errors/exceptions/connect.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def convert_exception(
6969
if "errorClass" in info.metadata:
7070
error_class = info.metadata["errorClass"]
7171

72+
if "messageParameters" in info.metadata:
73+
message_parameters = json.loads(info.metadata["messageParameters"])
74+
7275
stacktrace: Optional[str] = None
7376
if resp is not None and resp.HasField("root_error_idx"):
7477
message = resp.errors[resp.root_error_idx].message

python/pyspark/sql/tests/connect/test_connect_basic.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3486,6 +3486,17 @@ def test_can_create_multiple_sessions_to_different_remotes(self):
34863486
PySparkSession.builder.create()
34873487
self.assertIn("Create a new SparkSession is only supported with SparkConnect.", str(e))
34883488

3489+
def test_get_message_parameters_without_enriched_error(self):
3490+
with self.sql_conf({"spark.sql.connect.enrichError.enabled": False}):
3491+
exception = None
3492+
try:
3493+
self.spark.sql("""SELECT a""")
3494+
except AnalysisException as e:
3495+
exception = e
3496+
3497+
self.assertIsNotNone(exception)
3498+
self.assertEqual(exception.getMessageParameters(), {"objectName": "`a`"})
3499+
34893500

34903501
class SparkConnectSessionWithOptionsTest(unittest.TestCase):
34913502
def setUp(self) -> None:

0 commit comments

Comments
 (0)