<?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 workflow permissions errors in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/workflow-permissions-errors/m-p/86716#M37330</link>
    <description>&lt;P&gt;I have a notebook that outputs an Excel file. Through trial and error, and after consulting with various forums I discovered&amp;nbsp; the .xlsx file needed to be written to a temp file and then copied to the volume in Unity Catalog.&lt;/P&gt;&lt;P&gt;When I run the notebook by itself it works perfectly.&lt;/P&gt;&lt;P&gt;BUT, when I schedule the job in a workflow it fails with the following error:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;PermissionError: [Errno 13] Permission denied: '/local_disk0/tmp/202407-arf743-Section1.xlsx'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The workflow is using the same cluster as when I run the notebook alone.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The workflow has the "Run as" value set to my user ID.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any help would be appreciated&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 30 Aug 2024 01:32:24 GMT</pubDate>
    <dc:creator>BillMarshall</dc:creator>
    <dc:date>2024-08-30T01:32:24Z</dc:date>
    <item>
      <title>workflow permissions errors</title>
      <link>https://community.databricks.com/t5/data-engineering/workflow-permissions-errors/m-p/86716#M37330</link>
      <description>&lt;P&gt;I have a notebook that outputs an Excel file. Through trial and error, and after consulting with various forums I discovered&amp;nbsp; the .xlsx file needed to be written to a temp file and then copied to the volume in Unity Catalog.&lt;/P&gt;&lt;P&gt;When I run the notebook by itself it works perfectly.&lt;/P&gt;&lt;P&gt;BUT, when I schedule the job in a workflow it fails with the following error:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;PermissionError: [Errno 13] Permission denied: '/local_disk0/tmp/202407-arf743-Section1.xlsx'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The workflow is using the same cluster as when I run the notebook alone.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The workflow has the "Run as" value set to my user ID.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any help would be appreciated&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2024 01:32:24 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/workflow-permissions-errors/m-p/86716#M37330</guid>
      <dc:creator>BillMarshall</dc:creator>
      <dc:date>2024-08-30T01:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: workflow permissions errors</title>
      <link>https://community.databricks.com/t5/data-engineering/workflow-permissions-errors/m-p/88195#M37502</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/114530"&gt;@BillMarshall&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;I have a notebook that outputs an Excel file. Through trial and error, and after consulting with various forums I discovered&amp;nbsp; the .xlsx file needed to be written to a temp file and then copied to the volume in Unity Catalog.&lt;/P&gt;&lt;P&gt;When I run the notebook by itself it works perfectly.&lt;/P&gt;&lt;P&gt;BUT, when I schedule the job in a workflow it fails with the following error:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;PermissionError: [Errno 13] Permission denied: '/local_disk0/tmp/202407-arf743-Section1.xlsx'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The workflow is using the same cluster as when I run the notebook alone.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The workflow has the "Run as" value set to my user ID.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any help would be appreciated&lt;/SPAN&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;It sounds like you’re encountering a permissions issue when your workflow tries to write to the temporary directory. Here are a few steps you can take to troubleshoot and resolve this issue:&lt;/P&gt;&lt;P&gt;Check File Permissions: Ensure that the directory /local_disk0/tmp/ has the correct permissions set for your user. You can use the os.chmod() function in Python to change the file permissions if necessary1.&lt;BR /&gt;Verify User Permissions: Double-check that the user ID under which the workflow is running has the necessary permissions to write to the specified directory. Sometimes, even if the “Run as” value is set to your user ID, there might be additional restrictions in place.&lt;BR /&gt;Temporary Directory Path: Ensure that the path to the temporary directory is correctly specified and accessible. Sometimes, paths might differ slightly when running in different environments.&lt;BR /&gt;Cluster Configuration: Verify that the cluster configuration is consistent between running the notebook manually and running it as part of the workflow. There might be differences in environment variables or permissions.&lt;BR /&gt;Use a Different Temporary Directory: If possible, try using a different temporary directory that you know has the correct permissions. This can help isolate whether the issue is specific to the /local_disk0/tmp/ directory.&lt;BR /&gt;Check for Open Files: Ensure that the file isn’t being accessed by another process or application, which might be causing the permission error.&lt;BR /&gt;&lt;BR /&gt;Hope this will help you.&lt;BR /&gt;Best regards,&lt;BR /&gt;florence023&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 05:51:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/workflow-permissions-errors/m-p/88195#M37502</guid>
      <dc:creator>florence023</dc:creator>
      <dc:date>2024-09-04T05:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: workflow permissions errors</title>
      <link>https://community.databricks.com/t5/data-engineering/workflow-permissions-errors/m-p/88214#M37510</link>
      <description>&lt;P&gt;Hello, yes of course you need to write the excel file in the tmp folder, but then you can move it to whatever you want without problem. In my current project we implemented this method to create the file in the tmp folder, and then move it to one specific folder in an Azure Blob Container.&lt;/P&gt;&lt;P&gt;def export_to_excel(dbutils, df, file_name, result_path):&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;from pyspark.sql.functions import row_number, monotonically_increasing_id&lt;BR /&gt;from pyspark.sql import Window&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;# Const that means the excel limit rows&lt;BR /&gt;excel_limit = 1048576 - 1 # for header&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;num_rows = df.count()&lt;BR /&gt;num_files = num_rows / excel_limit&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;if num_files &amp;lt; 1:&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;with pd.ExcelWriter(f"/databricks/driver/{file_name}.xlsx", engine='xlsxwriter') as writer:&lt;/P&gt;&lt;P class="lia-indent-padding-left-90px"&gt;df_export = df.toPandas()&lt;BR /&gt;df_export.to_excel(writer, sheet_name=tab_names[0], index=False)&lt;BR /&gt;secondary_df.to_excel(writer, sheet_name=tab_names[1], index=False)&lt;BR /&gt;writer.save()&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;print("moving fileName: {0} from src directory: /databricks/driver/ to dst directory: {1} ".format(file_name, result_path))&lt;BR /&gt;dbutils.fs.mv(f"file:/databricks/driver/{file_name}.xlsx", f"{result_path}{file_name}.xlsx")&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;else:&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;df = df.withColumn("row_idx", row_number().over(Window.orderBy(monotonically_increasing_id())))&lt;/P&gt;&lt;P class="lia-indent-padding-left-60px"&gt;i = 0&lt;BR /&gt;while i &amp;lt; num_files:&lt;/P&gt;&lt;P class="lia-indent-padding-left-90px"&gt;df_export = df.filter((df.row_idx &amp;gt;= excel_limit*i) &amp;amp; (df.row_idx &amp;lt; excel_limit*(i+1)))&lt;/P&gt;&lt;P class="lia-indent-padding-left-90px"&gt;i = i+1&lt;BR /&gt;print('saving ' + str(df_export.count()) + ' rows in ' + file_name + '_part' + str(i) + '.xlsx')&lt;BR /&gt;df_export = df_export.drop(df_export.row_idx).toPandas()&lt;BR /&gt;# Save the file in the cluster path for no exceptions&lt;BR /&gt;df_export.to_excel("{0}_part{1}.xlsx".format(file_name, i), engine='xlsxwriter', index=False, header=True)&lt;BR /&gt;# move the file from cluster disk to dbfs&lt;BR /&gt;print("moving fileName: {0}_part{1} in src directory: /databricks/driver/ to dst directory: {2} ".format(file_name, i, result_path))&lt;BR /&gt;dbutils.fs.mv("file:/databricks/driver/{0}_part{1}.xlsx".format(file_name, i), "{2}{0}_part{1}.xlsx".format(file_name, i, result_path))&lt;/P&gt;&lt;P class="lia-indent-padding-left-90px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: You need to install the xlsxwritter python library, in order to be able to execute this method and generate the excel file.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 06:54:04 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/workflow-permissions-errors/m-p/88214#M37510</guid>
      <dc:creator>emora</dc:creator>
      <dc:date>2024-09-04T06:54:04Z</dc:date>
    </item>
  </channel>
</rss>

