How to catch exception from dbutils.widgets.get(...)
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2021 09:16 AM
I'm trying to write python notebook code that can be run from databricks web ui or from airflow. I intend to pass parameters from airflow via the job api using
notebook_params. From what I understand, these are accessible as widget values.
dbutils.widgets.get does not appear to accept a default value option so I assume I'll just have to catch an exception in case there isn't a value available. The code thrown on the UI ( InputWidgetNotDefined ) doesn't appear to work when I try catching it:
try:
test_val = dbutils.widgets.get("test_name")
except InputWidgetNotDefined:
test_val = "some default value"
print(test_val)
I can do a general, empty
except: which will work but is generally bad practice to do blanket catches if we can avoid it.
try:
test_val = dbutils.widgets.get("test_name")
except:
test_val = "some default value"
print(test_val)
So is there a more precise exception I can catch?