cancel
Showing results for 
Search instead for 
Did you mean: 
Data Governance
Join discussions on data governance practices, compliance, and security within the Databricks Community. Exchange strategies and insights to ensure data integrity and regulatory compliance.
cancel
Showing results for 
Search instead for 
Did you mean: 

Unity Catalog Shared Access Mode - dbutils.notebook.entry_point...getContext() not whitelisted

nccodemonkey
New Contributor III

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?

19 REPLIES 19

jdev220999
New Contributor II

Any updates on this problem?

Corbin
Databricks Employee
Databricks Employee

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:
Screenshot 2024-01-18 at 4.04.53 PM.png
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!

JakubMlacki
New Contributor III

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

this works here, thank you!

DouglasMoore
Databricks Employee
Databricks Employee

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__

 

Connect with Databricks Users in Your Area

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