โ02-14-2023 08:02 AM
we are switching over to Unity Catalog and attempting to confirm the ability to run our existing notebooks. I have created a new Shared Unity Catalog Cluster and ran the notebook using the new cluster. Ran into an error attempting to execute a print statement. The information is displayed using the original cluster, and will also display the information when running the UC cluster in a single Access mode, but NOT "Shared"
print(dbutils.notebook.entry_point.getDbutils().notebook().getContext().toJson())
Error Returned:
py4j.security.Py4JSecurityException: Method public java.lang.String com.databricks.backend.common.rpc.CommandContext.toJson() is not whitelisted on class class com.databricks.backend.common.rpc.CommandContext
Has anyone determined the appropriate work around for this scenario?
โ08-10-2023 07:26 AM
Any updates on this problem?
โ01-18-2024 07:06 AM - edited โ01-18-2024 07:12 AM
Depending on what you're trying to do with dbutils.notebook.entry_point.getDbutils().notebook().getContext().toJson() , there could be some workarounds. If all you're trying to do is get information like the job_id, run_id, time of run, etc. you can just use dynamic value references in the job. So for instance, in a notebook, you could say:
dbutils.widgets.text("job_id","")
job_id = dbutils.widgets.get("job_id")
Then in your task, when you specify params, you could use the dynamic value to pass the appropriate runtime value to the widget like so:
You can also do this as a job parameter if you need this value passed to all jobs.
Hope this helps someone who is using the context json for this simple purpose!
โ01-29-2024 09:49 AM
I faced the same issue when switching to Shared Access cluster and found that there is a possibility to run :
dbutils.notebook.entry_point.getDbutils().notebook().getContext().safeToJson()
Hope this helps
โ04-10-2024 06:50 PM
this works here, thank you!
3 weeks ago
To replace dbutils.notebook.entry_point.getDbutils().notebook().getContext().toJson() and related APIs try:
from dbruntime.databricks_repl_context import get_context
token = get_context().apiToken
host = get_context().browserHostName
get_context().__dict__
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโt want to miss the chance to attend and share knowledge.
If there isnโt a group near you, start one and help create a community that brings people together.
Request a New Group