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: 

How to abort/fail a notebook in databricks (and in datafactory)

tiagomotap5
New Contributor

Hello everyone!

I have a pipeline in Data Factory full of notebooks. In one of the notebooks I have the following (inside a function take writes a query to a table):

"

try:
df = spark.sql(query)
df.write.format(format).mode(method).saveAsTable(table)
except Exception as e:
(???)

"

And I want that if the code enters this "except Exception as e:" part, that the notebook abort (and that in the pipeline in DF the notebook shows as "failed").

I tried this methods:

1)

raise e

2)

raise Exception("error")

3)

assert False

4)

msg = "An error occured while writing the query to the table: {}".format(e)
dbutils.notebook.exit(msg)

 

None of them worked like I wanted. I want that the notebook fails. The last one actually stopped the rest of the cells from executing, but it still appears that was "successful" in Data Factory, and I want "failed".

Does anyone know how can I do this?

Please and thank you!! 😄

0 REPLIES 0

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