From 6feb9d181b78e588ff219ed35f6616d9c181c2e9 Mon Sep 17 00:00:00 2001 From: "@rugpanov" Date: Fri, 14 Aug 2026 15:52:02 +0200 Subject: [PATCH 1/2] fix(dbconnect-run): surface Databricks Connect import failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit *Why* The run bootstrap wrapped the Databricks Connect import and the session build in one broad try/except that logged any failure at debug level, so a broken environment produced no visible signal. The most common break is a standalone pyspark installed alongside databricks-connect: they share the pyspark package and overwrite each other, and the user only sees an opaque Java or protobuf gencode error from their own script, with no hint at the cause. *What* - Split the import from the session build. An import failure now logs at error level with actionable guidance naming the standalone-pyspark conflict, because the user's own script hits the same import. - A failure to *build* the session (no configured compute, auth) stays quiet at debug as before — many scripts create their own session and never use the injected one, so that path must not become noisy. *Verification* - python3 -m py_compile on the bootstrap script passes. Co-authored-by: Isaac --- .../resources/python/dbconnect-bootstrap.py | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/packages/databricks-vscode/resources/python/dbconnect-bootstrap.py b/packages/databricks-vscode/resources/python/dbconnect-bootstrap.py index f6a6c4f23..6b5ddde26 100644 --- a/packages/databricks-vscode/resources/python/dbconnect-bootstrap.py +++ b/packages/databricks-vscode/resources/python/dbconnect-bootstrap.py @@ -45,17 +45,35 @@ def load_env_from_leaf(path: str) -> bool: from databricks.sdk.runtime import dbutils # noqa: E402 db_globals['dbutils'] = dbutils -# "table", "sc", "sqlContext" are missing +# "table", "sc", "sqlContext" are missing. +# +# The import and the session build are handled separately on purpose. A failure to +# import Databricks Connect (or pyspark) means the Python environment itself is +# broken and the user's own script will hit the same error, so it is surfaced. The +# most common cause is a standalone "pyspark" package installed alongside +# databricks-connect: the two share the pyspark namespace and overwrite each other, +# and the resulting Java/protobuf error otherwise gives no hint at the cause. A +# failure to *build* the session (no configured compute, auth) is left quiet — many +# scripts create their own session and never touch the injected one. try: from pyspark.sql import functions as udf, SparkSession from databricks.connect import DatabricksSession - spark: SparkSession = DatabricksSession.builder.getOrCreate() - sql = spark.sql - db_globals['spark'] = spark - db_globals['sql'] = sql - db_globals['udf'] = udf except Exception as e: - logging.debug(f"Failed to create DatabricksSession: {e}") + logging.error( + "Failed to import Databricks Connect: %s. This usually means the Python " + "environment is misconfigured — a common cause is a standalone 'pyspark' " + "package installed alongside databricks-connect, which share the pyspark " + "package and overwrite each other. Remove the standalone pyspark dependency " + "and re-run 'Set up Python environment'.", e) +else: + try: + spark: SparkSession = DatabricksSession.builder.getOrCreate() + sql = spark.sql + db_globals['spark'] = spark + db_globals['sql'] = sql + db_globals['udf'] = udf + except Exception as e: + logging.debug(f"Failed to create DatabricksSession: {e}") # We do this to prevent importing widgets implementation prematurely # The widget import should prompt users to use the implementation From 2024d1b1d0873a60c3fdab23dac272c7cbcf3cf7 Mon Sep 17 00:00:00 2001 From: "@rugpanov" Date: Fri, 14 Aug 2026 16:09:11 +0200 Subject: [PATCH 2/2] fix(dbconnect-run): make the pyspark remediation conditional on the cause Review feedback (Codex, devil's-advocate, correctness pass): the import-error message stated "Remove the standalone pyspark dependency" as an unconditional instruction, but the import can fail for other reasons (databricks-connect not installed, another broken dependency). Phrase the fix conditionally so it is not misleading advice when pyspark is not the cause. Co-authored-by: Isaac --- .../resources/python/dbconnect-bootstrap.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/databricks-vscode/resources/python/dbconnect-bootstrap.py b/packages/databricks-vscode/resources/python/dbconnect-bootstrap.py index 6b5ddde26..6e2e7a312 100644 --- a/packages/databricks-vscode/resources/python/dbconnect-bootstrap.py +++ b/packages/databricks-vscode/resources/python/dbconnect-bootstrap.py @@ -61,10 +61,10 @@ def load_env_from_leaf(path: str) -> bool: except Exception as e: logging.error( "Failed to import Databricks Connect: %s. This usually means the Python " - "environment is misconfigured — a common cause is a standalone 'pyspark' " - "package installed alongside databricks-connect, which share the pyspark " - "package and overwrite each other. Remove the standalone pyspark dependency " - "and re-run 'Set up Python environment'.", e) + "environment is misconfigured. A common cause is a standalone 'pyspark' " + "package installed alongside databricks-connect: they share the pyspark " + "package and overwrite each other, so if your project depends on a " + "standalone pyspark, remove it and re-run 'Set up Python environment'.", e) else: try: spark: SparkSession = DatabricksSession.builder.getOrCreate()