<?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 Re: DAB: NameError: name '__file__' is not defined in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/dab-nameerror-name-file-is-not-defined/m-p/49913#M28645</link>
    <description>&lt;P&gt;Hi Kaniz,&lt;/P&gt;&lt;P&gt;Thank you for the answer.&lt;/P&gt;&lt;P&gt;Does it mean that this is limitation of asset bundles? If yes, it is anywhere listed as limitation?&lt;/P&gt;&lt;P&gt;Additionally, what does it mean that "&lt;SPAN&gt;&amp;nbsp;&lt;STRONG&gt;is not always&lt;/STRONG&gt; defined in Python scripts that are run using an asset bundle.&lt;/SPAN&gt;"&lt;/P&gt;&lt;P&gt;It is possible that it can be defined during run using DAB?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rafal&lt;/P&gt;</description>
    <pubDate>Thu, 26 Oct 2023 10:20:39 GMT</pubDate>
    <dc:creator>Rafal9</dc:creator>
    <dc:date>2023-10-26T10:20:39Z</dc:date>
    <item>
      <title>DAB: NameError: name '__file__' is not defined</title>
      <link>https://community.databricks.com/t5/data-engineering/dab-nameerror-name-file-is-not-defined/m-p/49906#M28641</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;I am running job task using Asset Bundle.&lt;/P&gt;&lt;P&gt;Bundle has been validated and deployed according to: &lt;A href="https://learn.microsoft.com/en-us/azure/databricks/dev-tools/bundles/work-tasks" target="_blank" rel="noopener"&gt;https://learn.microsoft.com/en-us/azure/databricks/dev-tools/bundles/work-tasks&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Part of the databricks.yml&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;bundle:
  name: etldatabricks

resources:
  jobs:
    etldatabricks-job:
      name: etldatabricks-job
      tasks:
        - task_key: etldatabricks-python-script-task
          existing_cluster_id: xxxx-17xx21-roxx
          spark_python_task:
            python_file: ./ingestion/my_script_dir/my_script.py

targets:
  dev: 
    mode: development
    default: true&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am receiving following error message during run of the my_script.py as a task in dev target via asset bundle.&lt;BR /&gt;NameError: name '__file__' is not defined&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# my_script.py

import sys
from pathlib import Path

from databricks.connect import DatabricksSession
from pyspark.sql import DataFrameWriter
from pyspark.sql.types import StructType, StructField, StringType

# add root dir to path
root_dir_path = Path(__file__).parent.parent.parent
sys.path.append(str(root_dir_path))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot understand why python dunder __file__ variable cannot be resolved running the script via DAB.&lt;/P&gt;&lt;P&gt;File of course works without any issues during standard databricks job run.&lt;/P&gt;&lt;P&gt;Thank you for any help.&lt;/P&gt;&lt;P&gt;Rafal&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 10:01:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/dab-nameerror-name-file-is-not-defined/m-p/49906#M28641</guid>
      <dc:creator>Rafal9</dc:creator>
      <dc:date>2023-10-26T10:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: DAB: NameError: name '__file__' is not defined</title>
      <link>https://community.databricks.com/t5/data-engineering/dab-nameerror-name-file-is-not-defined/m-p/49913#M28645</link>
      <description>&lt;P&gt;Hi Kaniz,&lt;/P&gt;&lt;P&gt;Thank you for the answer.&lt;/P&gt;&lt;P&gt;Does it mean that this is limitation of asset bundles? If yes, it is anywhere listed as limitation?&lt;/P&gt;&lt;P&gt;Additionally, what does it mean that "&lt;SPAN&gt;&amp;nbsp;&lt;STRONG&gt;is not always&lt;/STRONG&gt; defined in Python scripts that are run using an asset bundle.&lt;/SPAN&gt;"&lt;/P&gt;&lt;P&gt;It is possible that it can be defined during run using DAB?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rafal&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 10:20:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/dab-nameerror-name-file-is-not-defined/m-p/49913#M28645</guid>
      <dc:creator>Rafal9</dc:creator>
      <dc:date>2023-10-26T10:20:39Z</dc:date>
    </item>
  </channel>
</rss>

