cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Why my notebook I created in a Repo can be opened safe?

dnchankov
New Contributor II

I've cloned a Repo during "Get Started with Data Engineering on Databricks".

Then I'm trying to run another notebook from a cell with a magic %run command.

But I get that the file can't be opened safe.

Here my code:

notebook_a

name = "John"
print(f"Hello {name}")
%run ./notebook_b3
print(f"Welcome back John {full_name2}")

notebook_b3:

full_name2 = "Todorov"

Error

/databricks/python/lib/python3.10/site-packages/IPython/core/interactiveshell.py:2807: UserWarning: Could not open file </Workspace/Repos/dnchankov@abv.bg/my_databricks_course/my_folder/notebook_b3> for safe execution.
  warn('Could not open file <%s> for safe execution.' % fname)
NameError: name 'full_name2' is not defined

Thanks in advance!

๐Ÿ™‚

3 ACCEPTED SOLUTIONS

Accepted Solutions

petermeissner
New Contributor III

It could be that you need to put the %run in a cell all by itself. 

Suggested here: https://stackoverflow.com/a/72833400/1144966

View solution in original post

cbossi
New Contributor III

Hi,
 
Just sharing this here for future reference in case it helps other users. 
I ran into the same warning/error, and the solution is indeed what @petermeissner pointed out.
 
The %run command must be in a cell by itself.
In my case, having a comment in the `%run` cell was the reason the error occurred.

View solution in original post

iyashk-DB
Databricks Employee
Databricks Employee

+1 to all the above comments. Having the %run command along with other commands will confuse the REPL execution. So, have the %run notebook_b3 command alone in a new cell, maybe as the first cell, is notebook_a, which will resolve the issue, and your variables can also be accessed anywhere in notebook_a.

View solution in original post

5 REPLIES 5

Anonymous
Not applicable

Hi @Dobromir Chankovโ€‹ 

Great to meet you, and thanks for your question!

Let's see if your peers in the community have an answer to your question. Thanks.

Anonymous
Not applicable

Opening in Confined Mode is the most secure choice and you can constantly resume the record in your unique Versus Code window once you decide the document is reliable.

Custom Labels and Stickers | Custom Boxes With Logo

petermeissner
New Contributor III

It could be that you need to put the %run in a cell all by itself. 

Suggested here: https://stackoverflow.com/a/72833400/1144966

cbossi
New Contributor III

Hi,
 
Just sharing this here for future reference in case it helps other users. 
I ran into the same warning/error, and the solution is indeed what @petermeissner pointed out.
 
The %run command must be in a cell by itself.
In my case, having a comment in the `%run` cell was the reason the error occurred.

iyashk-DB
Databricks Employee
Databricks Employee

+1 to all the above comments. Having the %run command along with other commands will confuse the REPL execution. So, have the %run notebook_b3 command alone in a new cell, maybe as the first cell, is notebook_a, which will resolve the issue, and your variables can also be accessed anywhere in notebook_a.