PlantOps BI

Notebook saveAsTable Fails: The Default Lakehouse Isn’t Attached

Skip to the fix

Symptom

A notebook that ends each step with saveAsTable fails on the first write if it runs before a lakehouse is attached. The exact error string isn’t recorded here, so I can’t quote it.

Cause

The notebook has no lakehouse attached, so there is no default lakehouse for the table to land in. A notebook imported into a workspace starts out this way, so running it straight away runs into this.

Fix

  1. In the notebook, choose Add data items, then From OneLake catalog, and pick the lakehouse.
  2. Set it as the default. That option only shows up after you have added a lakehouse, so you will not find it beforehand.
  3. Restart the session. Attaching the default lakehouse requires a session restart before it takes effect.
  4. Run all.

How I Proved It

After attaching the lakehouse as the default and restarting, Run all finished 20 of 20 Spark jobs in about 1 minute 16 seconds and wrote all 13 Delta tables. The largest was a production table with 155,340 rows, and an orders table had 45,042. Because the notebook regenerates the seeded data every run, I can rerun it at any time to rebuild the lakehouse from scratch.

If your notebook is going to be imported more than once, say so in its first cell: attach the lakehouse before you run anything.