Home / Databricks on Azure

Databricks on AzureTroubleshootingIntermediate

Writing files to Unity Catalog volumes fails on Azure Databricks: Excel, zip, append and random-write errors

Python code that writes Excel, zip, SQLite or appended logs to /Volumes fails or leaves broken files. Find which write pattern is the problem, build the file on local disk, then copy it in.

Deepak Bhardwaj7 min read

Applies toAzure Databricks with Unity Catalog, Databricks Runtime 13.3 LTS and later, serverless notebooks and jobs, Databricks CLI (new)

Symptom

A notebook or job reads from a Unity Catalog volume without trouble, but writing a file to /Volumes/... fails, or the file it leaves behind is corrupt. Typical cases:

  • df.to_excel("/Volumes/main/finance/exports/report.xlsx") raises an OSError, or the file won't open in Excel afterwards.
  • zipfile.ZipFile("/Volumes/.../bundle.zip", "w") fails partway through.
  • A SQLite database, or any library that seeks inside a file it is writing, fails on /Volumes.
  • open(path, "a") for a log file fails, or the file only ever holds the last write.
  • A plain df.to_csv(...) or shutil.copy(...) into the same volume works fine.

The error text depends on the library and runtime. You often see OSError: [Errno 95] Operation not supported, but some libraries only print a generic I/O error or a "bad zip file" message when the file is read back.

Why it happens

Volumes are backed by object storage (ADLS Gen2). The /Volumes POSIX path goes through a FUSE layer that supports sequential writes of a whole file. It does not support direct appends or non-sequential (random) writes. The Databricks documentation lists Zip and Excel files as examples of what this affects.

Any library that writes a file, seeks back to patch a header or index, and then keeps writing will hit this limit:

Write pattern Example libraries / code Works on /Volumes?
Write the whole file sequentially to_csv, to_parquet, json.dump, shutil.copy, dbutils.fs.cp Yes
Spark writer to a directory df.write.format("delta").save("/Volumes/...") Yes
Seek and rewrite parts of the file openpyxl/xlsxwriter Excel, zipfile, tarfile with some modes, SQLite, HDF5 No: write locally, then copy
Append to an existing file open(p, "a"), the logging.FileHandler default mode No: write locally, then copy
Sparse files Some database and VM image tooling No: copy with cp --sparse=never

Warning

A failed random write can still leave a partly written file at the target path. Downstream jobs that pick up "any new file in the folder" will ingest a broken workbook or archive. Clean up the target path before you rerun.

Checks

1. Confirm it's the write pattern, not permissions

Write a small sequential file to the same folder:

path = "/Volumes/main/finance/exports/_write_test.txt"
with open(path, "w") as f:
    f.write("ok\n")
print(open(path).read())
dbutils.fs.rm(path)

If this fails too, the problem is permissions or access mode (see the table further down), not the library. If it works, the library's write pattern is the cause.

2. Check grants on the volume

Writing needs WRITE VOLUME on the volume, plus USE CATALOG and USE SCHEMA on its parents:

SHOW GRANTS ON VOLUME main.finance.exports;

-- Grant to the group or service principal that runs the job
GRANT USE CATALOG ON CATALOG main TO `finance-etl`;
GRANT USE SCHEMA ON SCHEMA main.finance TO `finance-etl`;
GRANT READ VOLUME, WRITE VOLUME ON VOLUME main.finance.exports TO `finance-etl`;

For a job, check the run as identity, not your own account. A notebook that works interactively can fail as a job because the job runs as a service principal that has no grants.

3. Check the compute access mode

Volumes need Unity Catalog compute: serverless, or a cluster in standard (formerly shared) or dedicated (formerly single user) access mode. On a legacy "No isolation shared" cluster, /Volumes paths are not available. Check the cluster's access mode:

databricks clusters get 0612-091500-abcd1234 --output json | jq '.data_security_mode'

USER_ISOLATION (standard) and SINGLE_USER (dedicated) support volumes. NONE doesn't. Access mode names vary between the UI, the API and older runtimes, so check your build's output.

4. External volume: check the storage firewall

If the volume is external and writes fail with 403 or AuthorizationFailure, the ADLS account's firewall or the access connector's role is the cause, not the write pattern. Fix the network and role first.

Fix: build the file on local disk, then copy it in

The fix is the one the documentation recommends: do the random-write or append work on the node's local disk, then copy the finished file to the volume in one sequential write.

Excel

import os, shutil, tempfile
import pandas as pd

pdf = spark.table("main.finance.monthly_summary").toPandas()

target = "/Volumes/main/finance/exports/monthly_summary.xlsx"
with tempfile.TemporaryDirectory() as tmp:
    local = os.path.join(tmp, "monthly_summary.xlsx")
    pdf.to_excel(local, index=False, sheet_name="summary")   # needs openpyxl
    shutil.copy(local, target)                               # single sequential write

Zip archives

import os, shutil, tempfile, zipfile

src_dir = "/Volumes/main/finance/exports/daily"
target  = "/Volumes/main/finance/exports/archive/daily_2026-11-14.zip"

with tempfile.TemporaryDirectory() as tmp:
    local_zip = os.path.join(tmp, "daily.zip")
    with zipfile.ZipFile(local_zip, "w", compression=zipfile.ZIP_DEFLATED) as z:
        for name in os.listdir(src_dir):               # reading from /Volumes is fine
            z.write(os.path.join(src_dir, name), arcname=name)
    shutil.copy(local_zip, target)

Reading a zip from a volume works. If extraction fails, copy the archive to local disk first and extract it there.

SQLite or other file databases

import shutil, sqlite3

local_db = "/tmp/lookup.db"
shutil.copy("/Volumes/main/ref/files/lookup.db", local_db)   # pull down
con = sqlite3.connect(local_db)
con.execute("UPDATE codes SET active = 0 WHERE code = 'X1'")
con.commit(); con.close()
shutil.copy(local_db, "/Volumes/main/ref/files/lookup.db")   # push back

Caution

Pushing back a whole file overwrites the copy in the volume. If two jobs do this at the same time, the last one to finish wins and the other job's changes are lost. Serialise these jobs (max concurrent runs = 1), or move the data into a Delta table.

Append-style logs

Don't append to one file in a volume. Either write one file per run:

import datetime, json
run_ts = datetime.datetime.utcnow().strftime("%Y%m%dT%H%M%S")
with open(f"/Volumes/main/ops/logs/myjob/run_{run_ts}.json", "w") as f:
    json.dump({"status": "ok", "rows": 1234}, f)

or buffer in /tmp during the run and copy the file once at the end. For anything you query later, write rows to a Delta table instead. It handles concurrent appends and can be queried with SQL.

Moving files with dbutils or the CLI

dbutils.fs.cp and the CLI both copy whole files, so they are safe ways to move a locally built file:

dbutils.fs.cp("file:/tmp/report.xlsx", "/Volumes/main/finance/exports/report.xlsx")
databricks fs cp ./report.xlsx dbfs:/Volumes/main/finance/exports/report.xlsx --overwrite
databricks fs ls dbfs:/Volumes/main/finance/exports/

Quick symptom map

Symptom Likely cause Fix
Errno 95 / I/O error only for xlsx, zip, sqlite Random writes on FUSE Build locally, copy in
Log file holds only the last line, or append fails Direct append not supported One file per run, or a Delta table
Every write fails, even a small text file Missing WRITE VOLUME or USE SCHEMA GRANT to the job's run-as identity
/Volumes path not found Cluster access mode without Unity Catalog Use standard, dedicated or serverless compute
403 on an external volume only Storage firewall or access connector role Fix network rules and the role assignment
Downstream job reads a corrupt file A failed write left a partial file Write to a temp name, then rename or copy as the last step

Prevent it next time

  • Put a shared helper in your wheel or utility module, write_via_local(build_fn, target_path), that always builds in a temp directory and copies in. Teams then don't hit this one library at a time.
  • Have producers write to a temp file name (for example _tmp_report.xlsx) and copy or rename it to the final name as the last step. Point consumers and file arrival triggers only at final names.
  • Keep logs, audit rows and run metadata in Delta tables, not in appended files.
  • Test new export code on the same compute type the job uses (serverless or standard access mode), not just on a dedicated cluster.
  • Check the local disk space on the driver when you build large archives. /tmp lives on the node's local disk, and building a large archive there can fill it.