Search code examples
databricksazure-databricks

Unable to run databricks notebook from another notebook with dbutils.notebook.run("mynotebook", 3600)


When I attempt run a notebook from another databricks notebook with the dbutils.notebook.run("mynotebook", 3600) I get the error:

com.databricks.WorkflowException: com.databricks.NotebookExecutionException: FAILED: Unable to access the notebook "/Users/[email protected]/path/mynotebooks". Either it does not exist, or the identity used to run this job, xxxxxx ([email protected]), lacks the required permissions.

However, I can successfully run the notebook using the following:

%run "/path/mynotebook"

Can someone let me know why I'm getting the error suggesting I don't have the permissions to execute the notebook with dbutils.notebook.run("mynotebook", 3600)


Solution

  • I have tried the below approach:

    dbutils.notebook.run("./child", 3600)
    

    enter image description here

    This function will execute the specified notebook (child) in a new notebook context, allowing you to run code in the child notebook independently from the parent notebook.

    Child Notebook:

    child_variable =  "this is child variable"
    dbutils.notebook.exit(child_variable)
    
      Notebook exited: this is child variable
    

    The dbutils.notebook function syntax is as follows:

    dbutils.notebook.run(notebookpath, timeout_in_seconds, parameters)
    

    The dbutils.notebook function takes three arguments:

    Notebook_path: The path of the target notebook to be executed.

    Timeout_in_seconds: The maximum time in seconds the notebook is allowed to run before throwing an exception.

    parameters: A JSON-formatted string used to send parameters to the child notebook. Parameters should be specified as key-value pairs, e.g., {'parameter1': 'value1', 'parameter2': 'value2'}.

    Reference: Call a notebook from another notebook in Databricks