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?

18 REPLIES 18

jdev220999
New Contributor II

Any updates on this problem?

Corbin
New Contributor III
New Contributor III

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 II

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!

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!