<?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 Change Default Lakehouse in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4372236#M6258</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;In a notebook which is in DEV I use this code to get the ID of the Lakehouse in DEV and the ID of the Workspace DEV :&lt;/P&gt;&lt;PRE&gt;df_Lakehouse = labs.list_lakehouses()&lt;BR /&gt;lakehouse_row = df_Lakehouses[df_lakehouses["Lakehouse Name"] == "Lakehouse"]&lt;BR /&gt;lakehouse_id = lakehouse_row.iloc[0]["Lakehouse ID]&lt;BR /&gt;workspace_id = spark.conf.get("trident.workspace.id)&lt;/PRE&gt;&lt;P&gt;And I'd like to add the IDs to this code, but unfortunately I can't set the variables correctly for the code to work.&lt;/P&gt;&lt;PRE&gt;%%configure -f&lt;BR /&gt;{&lt;BR /&gt;    "defaultLakehouse": {&lt;BR /&gt;     "name": 'Lakehouse',&lt;BR /&gt;     "id": lakehouse_id,&lt;BR /&gt;     "workspace": workspace_id&lt;BR /&gt;     }&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have any ideas?&lt;/P&gt;</description>
    <pubDate>Mon, 20 Jan 2025 16:16:08 GMT</pubDate>
    <dc:creator>Charline_74</dc:creator>
    <dc:date>2025-01-20T16:16:08Z</dc:date>
    <item>
      <title>Change Default Lakehouse</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4372236#M6258</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;In a notebook which is in DEV I use this code to get the ID of the Lakehouse in DEV and the ID of the Workspace DEV :&lt;/P&gt;&lt;PRE&gt;df_Lakehouse = labs.list_lakehouses()&lt;BR /&gt;lakehouse_row = df_Lakehouses[df_lakehouses["Lakehouse Name"] == "Lakehouse"]&lt;BR /&gt;lakehouse_id = lakehouse_row.iloc[0]["Lakehouse ID]&lt;BR /&gt;workspace_id = spark.conf.get("trident.workspace.id)&lt;/PRE&gt;&lt;P&gt;And I'd like to add the IDs to this code, but unfortunately I can't set the variables correctly for the code to work.&lt;/P&gt;&lt;PRE&gt;%%configure -f&lt;BR /&gt;{&lt;BR /&gt;    "defaultLakehouse": {&lt;BR /&gt;     "name": 'Lakehouse',&lt;BR /&gt;     "id": lakehouse_id,&lt;BR /&gt;     "workspace": workspace_id&lt;BR /&gt;     }&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have any ideas?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 16:16:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4372236#M6258</guid>
      <dc:creator>Charline_74</dc:creator>
      <dc:date>2025-01-20T16:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Change Default Lakehouse</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4372291#M6263</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/475779"&gt;@Charline_74&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To change the default lakehouse in a Microsoft Fabric notebook, you can use the&amp;nbsp;%%configure&amp;nbsp;magic command with the&amp;nbsp;defaultLakehouse&amp;nbsp;parameter. However, the issue in your code is that you're trying to use Python variables directly within the JSON configuration, which isn't possible. Instead, you need to format the JSON string with the variable values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;could you please give this a try :&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;df_Lakehouses = labs.list_lakehouses()&lt;BR /&gt;lakehouse_row = df_Lakehouses[df_Lakehouses["Lakehouse Name"] == "Lakehouse"]&lt;BR /&gt;lakehouse_id = lakehouse_row.iloc[0]["Lakehouse ID"]&lt;BR /&gt;workspace_id = spark.conf.get("trident.workspace.id")&lt;/P&gt;&lt;P&gt;%%configure -f&lt;BR /&gt;{&lt;BR /&gt;"defaultLakehouse": {&lt;BR /&gt;"name": "Lakehouse",&lt;BR /&gt;"id": "%s",&lt;BR /&gt;"workspaceId": "%s"&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;""" % (lakehouse_id, workspace_id)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Please give kudos and mark this as solution if this helps.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 17:25:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4372291#M6263</guid>
      <dc:creator>nilendraFabric</dc:creator>
      <dc:date>2025-01-20T17:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: Change Default Lakehouse</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4372354#M6271</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/475779"&gt;@Charline_74&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;to add on what&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/913195"&gt;@nilendraFabric&lt;/a&gt;&amp;nbsp;said, using the configure command to overwrite notebook metadata, such as the default lakehouse, will require you to restart the running session. This leads to problem when executing the notebook from a scheduler such as a Data Pipeline. This should be taken into account when relying on this option.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As an alternative to changing the default lakehouse within the same notebook, you could try to use the Fabric API and change the default lakehouse reference from a separate notebook.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 19:37:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4372354#M6271</guid>
      <dc:creator>ObungiNiels</dc:creator>
      <dc:date>2025-01-20T19:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Change Default Lakehouse</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4373250#M6302</link>
      <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/475779"&gt;@Charline_74&lt;/a&gt;&amp;nbsp;could you please accept this as solution if this resolved your query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 08:55:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4373250#M6302</guid>
      <dc:creator>nilendraFabric</dc:creator>
      <dc:date>2025-01-21T08:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Change Default Lakehouse</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4373251#M6303</link>
      <description>&lt;P&gt;Thank you for your feedback. Do you know how to use this API? &lt;A href="https://learn.microsoft.com/en-us/rest/api/fabric/notebook/items/update-notebook-definition?tabs=HTTP" target="_blank"&gt;https://learn.microsoft.com/en-us/rest/api/fabric/notebook/items/update-notebook-definition?tabs=HTTP&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I don't understand how to define the API body?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jan 2025 08:56:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4373251#M6303</guid>
      <dc:creator>Charline_74</dc:creator>
      <dc:date>2025-01-21T08:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Change Default Lakehouse</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4376240#M6391</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/475779"&gt;@Charline_74&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just tried it out and you can change the notebook definition including metdata using notebookutils, so we don't even need to explicitely invoke an API call. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what worked for me:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import sempy.fabric as fabric

# INSERT YOUR WORKSPACES SPECIFIC INFORMATION HERE

workspace_name = "workspace_id"
item_name = "notebook_name"

replacement_dict = {
    "lakehouse_id" : {
        "old" : "LH_ID_old",
        "new" : "LH_ID_new",
    },
    "lakehouse_name" : {
        "old" : "LH_old",
        "new" : "LH_new",
    },
    "workspace_id_of_lakehouse" : {
        "old" : "workspace_id_old",
        "new" : "workspace_id_new",
    },
}

workspace_id = fabric.resolve_workspace_id(workspace_name)
items = fabric.list_items(workspace=workspace_name)
item_id = items.where(items["Display Name"] == f"{item_name}").dropna().Id.item()
item_type = items.where(items["Display Name"] == f"{item_name}").dropna().Type.item()

definition = notebookutils.notebook.getDefinition(item_name, workspace_id)

for replacement in replacement_dict.keys():
    definition = definition.replace(replacement_dict[replacement]["old"], replacement_dict[replacement]["new"])

notebookutils.notebook.updateDefinition(name=item_name, content=definition, workspaceId=workspace_id)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is essentially doing a search and replace in the current definition of your notebook and overwrites the specific part concerning the default lakehouse. If your items are in the same workspace you could skip the "workspace_id_of_lakehouse" key in the dict since it doesn't need to be changed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We found great success using these commands to change information which for instance cannot be parametrized during deployment via (the current form of) deployment pipelines.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps you out. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 17:28:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4376240#M6391</guid>
      <dc:creator>ObungiNiels</dc:creator>
      <dc:date>2025-01-22T17:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: Change Default Lakehouse</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4760269#M10827</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm getting the following error when trying this solution:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN class=""&gt;Cell &lt;/SPAN&gt;&lt;SPAN class=""&gt;In[17], line 14&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN class=""&gt;""" % (lakehouse_id, workspace_id)&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;^&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN class=""&gt;SyntaxError&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;SPAN&gt; incomplete input&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When moving the configure magic to it's own cell I get this error:&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;MagicUsageError: Configuration should be a valid JSON object expression. &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;SPAN&gt;--&amp;gt; JsonReaderException: After parsing a value an unexpected character was encountered: ". Path 'defaultLakehouse', line 7, position 0.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Tried multiple variations of it, but I can't seem to figure it out. Appreciate any help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jul 2025 15:44:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Change-Default-Lakehouse/m-p/4760269#M10827</guid>
      <dc:creator>PANDAmonium</dc:creator>
      <dc:date>2025-07-11T15:44:07Z</dc:date>
    </item>
  </channel>
</rss>

