Skip to content

Commit 4a00f9c

Browse files
Add exception handlers to bootstrap python code (#1133)
## Changes * Our bootstrap for python files (running using both workflows and command execution API), is failing because Db connect does not support jvm context and dbconnect is the default spark implementation from dbr 14.x. * This PR adds exception handlers to maintain backwards compatibilty. Fixes #1123 ## Tests <!-- How is this tested? -->
1 parent e7f8e51 commit 4a00f9c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

packages/databricks-vscode/resources/python/bootstrap.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@
3737
}
3838

3939
# Set log level to "ERROR". See https://kb.databricks.com/notebooks/cmd-c-on-object-id-p0.html
40-
import logging; logger = spark._jvm.org.apache.log4j;
41-
logging.getLogger("py4j.java_gateway").setLevel(logging.ERROR)
40+
try:
41+
import logging; logger = spark._jvm.org.apache.log4j;
42+
logging.getLogger("py4j.java_gateway").setLevel(logging.ERROR)
43+
except Exception as e:
44+
logging.debug("Failed to set py4j.java_gateway log level to ERROR", exc_info=True)
45+
pass
4246

4347
runpy.run_path(python_file, run_name="__main__", init_globals=user_ns)
4448
None

packages/databricks-vscode/resources/python/file.workflow-wrapper.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
"sqlContext": sqlContext,
2828
}
2929

30-
# Set log level to "ERROR". See https://kb.databricks.com/notebooks/cmd-c-on-object-id-p0.html
31-
import logging; logger = spark._jvm.org.apache.log4j;
32-
logging.getLogger("py4j.java_gateway").setLevel(logging.ERROR)
30+
try:
31+
# Set log level to "ERROR". See https://kb.databricks.com/notebooks/cmd-c-on-object-id-p0.html
32+
import logging; logger = spark._jvm.org.apache.log4j;
33+
logging.getLogger("py4j.java_gateway").setLevel(logging.ERROR)
34+
except Exception as e:
35+
logging.debug("Failed to set py4j.java_gateway log level to ERROR", exc_info=True)
36+
pass
3337

3438
runpy.run_path(python_file, run_name="__main__", init_globals=user_ns)
3539
None

0 commit comments

Comments
 (0)