Forum Discussion

truls_sg's avatar
truls_sg
Frequent Visitor
1 year ago
Solved

Creating files via lakehouse shortcut

Hi

I have two lakehouses, call them lh1 and lh2, and there is a shortcut from lh1 to lh2

 

When trying to create a file via the shortcut, I get an error if the file does not already exist on the path. If the file already exists on the path, then the write operation works fine.

 

Example:

data = {"name": "John Doe", "age": 30, "city": "New York"}

with open("/lakehouse/default/Files/shortcut_folder/data.json", "w", encoding="utf-8") as file:
     json.dump(data, file, indent=4, ensure_ascii=False)
 
If the file exists on path, the code runs fine via the shortcut (running with lh2 as default for the notebook").
If the file does not exist on path, I get an error saying no such file or directory when running with lh2 as default
If the file does not exist on path, but I run with lh1 as default lakehouse, there is no problem
 
In summary; I can write to a file via a shortcut, only if that file exists on path prior to me writing to the file (has been created with lh1 as default lakehouse). Then to me it does not look like a access problem since I can write and append an already existing file. What is happening here?
  • Hi truls_sg ,

    Thank you for reaching out to Microsoft Fabric Community.

    The issue occurs because shortcuts in Fabric lakehouses are read-only, meaning you can't create new files or folders through them - only read or overwrite existing files. That's why your code works only if the file already exists.

    Set lh1 (the source lakehouse of the shortcut) as your default lakehouse in the notebook when writing files. This allows you to create new files successfully:

    data = {"name": "John Doe", "age": 30, "city": "New York"}

    with open("/lakehouse/default/Files/shortcut_folder/data.json", "w", encoding="utf-8") as file:
    json.dump(data, file, indent=4, ensure_ascii=False)

    If you're using lh2 as default, writing to a shortcut will only work for existing files - creation is blocked by design.

     

    If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

    Thank you.

2 Replies

  • v-venuppu's avatar
    v-venuppu
    Icon for Community Support rankCommunity Support

    Hi truls_sg ,

    Thank you for reaching out to Microsoft Fabric Community.

    The issue occurs because shortcuts in Fabric lakehouses are read-only, meaning you can't create new files or folders through them - only read or overwrite existing files. That's why your code works only if the file already exists.

    Set lh1 (the source lakehouse of the shortcut) as your default lakehouse in the notebook when writing files. This allows you to create new files successfully:

    data = {"name": "John Doe", "age": 30, "city": "New York"}

    with open("/lakehouse/default/Files/shortcut_folder/data.json", "w", encoding="utf-8") as file:
    json.dump(data, file, indent=4, ensure_ascii=False)

    If you're using lh2 as default, writing to a shortcut will only work for existing files - creation is blocked by design.

     

    If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

    Thank you.

    • truls_sg's avatar
      truls_sg
      Frequent Visitor

      So that is where my confusion comes in, becuase in my experience read only access usually does not allow you to modify existing files. 

      Thank you for the answer!