<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to abort/fail a notebook in databricks (and in datafactory) in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-abort-fail-a-notebook-in-databricks-and-in-datafactory/m-p/38687#M26718</link>
    <description>&lt;P&gt;Hello everyone!&lt;/P&gt;&lt;P&gt;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):&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = spark.sql(query)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df.write.format(format).mode(method).saveAsTable(table)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;except Exception as e:&lt;/SPAN&gt;&lt;BR /&gt;(???)&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;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").&lt;/P&gt;&lt;P&gt;I tried this methods:&lt;/P&gt;&lt;P&gt;1)&lt;/P&gt;&lt;P&gt;raise e&lt;/P&gt;&lt;P&gt;2)&lt;/P&gt;&lt;P&gt;raise Exception("error")&lt;/P&gt;&lt;P&gt;3)&lt;/P&gt;&lt;P&gt;assert False&lt;/P&gt;&lt;P&gt;4)&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;msg = "An error occured while writing the query to the table: {}".format(e)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dbutils.notebook.exit(msg)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;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".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Does anyone know how can I do this?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please and thank you!! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jul 2023 16:29:12 GMT</pubDate>
    <dc:creator>tiagomotap5</dc:creator>
    <dc:date>2023-07-28T16:29:12Z</dc:date>
    <item>
      <title>How to abort/fail a notebook in databricks (and in datafactory)</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-abort-fail-a-notebook-in-databricks-and-in-datafactory/m-p/38687#M26718</link>
      <description>&lt;P&gt;Hello everyone!&lt;/P&gt;&lt;P&gt;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):&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = spark.sql(query)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df.write.format(format).mode(method).saveAsTable(table)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;except Exception as e:&lt;/SPAN&gt;&lt;BR /&gt;(???)&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;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").&lt;/P&gt;&lt;P&gt;I tried this methods:&lt;/P&gt;&lt;P&gt;1)&lt;/P&gt;&lt;P&gt;raise e&lt;/P&gt;&lt;P&gt;2)&lt;/P&gt;&lt;P&gt;raise Exception("error")&lt;/P&gt;&lt;P&gt;3)&lt;/P&gt;&lt;P&gt;assert False&lt;/P&gt;&lt;P&gt;4)&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;msg = "An error occured while writing the query to the table: {}".format(e)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dbutils.notebook.exit(msg)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;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".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Does anyone know how can I do this?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please and thank you!! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 16:29:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-abort-fail-a-notebook-in-databricks-and-in-datafactory/m-p/38687#M26718</guid>
      <dc:creator>tiagomotap5</dc:creator>
      <dc:date>2023-07-28T16:29:12Z</dc:date>
    </item>
  </channel>
</rss>

