The Databricks widget (dbutils) provides the get function for accessing the job parameters of a job.
dbutils.widgets.get('my_param')
Unlike Python dict, where get returns None or an optional argument if the dict doesn't contain the parameter, the widget get will raise an error if there is no such parameter. The benefit of this design I guess is to promote failing early.
However, if you want an optional parameter in a PySpark script, is there a better way to implement this than to try to catch this error and defaulting from there? I noticed that there is a deprecated getArgument that does exactly this. However it is deprecated.
It also says that it is equivalent to get, but this is clearly not true as getArgument has the option of a default value.
dbutils.widgets.help()
get(name: String): String -> Retrieves current value of an input widget
getArgument(name: String, optional: String): String -> (DEPRECATED) Equivalent to get
test = dbutils.widgets.getArgument('test2', 'bla2')
print(test)
That seems like a bug.