<?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 Re: Notebook with sempy_labs failed when executed in DataPipeline in Pipelines</title>
    <link>https://community.fabric.microsoft.com/t5/Pipelines/Notebook-with-sempy-labs-failed-when-executed-in-DataPipeline/m-p/5156078#M9366</link>
    <description>&lt;P&gt;I found an article from semantic-link-labs (&lt;A href="https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb" target="_blank" rel="noopener"&gt;semantic-link-labs/notebooks/Service Principal.ipynb at main · microsoft/semantic-link-labs · GitHub&lt;/A&gt;) and adjusted my function accordingly.&lt;BR /&gt;Everything works except the&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;directlake.update_direct_lake_model_connection() &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;with error:&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;FONT size="2" color="#FF0000"&gt;ConnectionException&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;FONT size="2" color="#FF0000"&gt;The specified Power BI workspace ('6e33da9d-a067-4519-a893-b9aa0d867d95') is not found. Technical Details: RootActivityId: 4b87e95d-5bd9-4418-87e4-a320b18fda4b Workspace: '6e33da9d-a067-4519-a893-b9aa0d867d95' at Microsoft.AnalysisServices.ConnectionInfo.ResolveHTTPConnectionProperties&lt;/FONT&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def main():

    stage("Resolve Context")

    targetWorkspaceId = workspaceId
    targetLakehouseId = lakehouseId

    if not targetWorkspaceId:
        raise ValueError(f"Workspace not found: {TARGET_WORKSPACE_NAME}")

    if not targetLakehouseId:
        raise ValueError(f"Lakehouse not found: {LAKEHOUSE_NAME}")

    stage("Check Existing Assets")

    smExists = semanticModelExists(
        targetWorkspaceId,
        TARGET_SEMANTICMODEL_NAME
    )

    repExists = reportExists(
        targetWorkspaceId,
        SOURCE_REPORT_NAME
    )

    logger.info(f"Semantic model exists: {smExists}")
    logger.info(f"Report exists: {repExists}")

    # --------------------------------------------------
    # AUTHENTICATION BLOCK (IMPORTANT)
    # --------------------------------------------------

    with labs.service_principal_authentication(
        key_vault_uri=key_vault_uri, 
    key_vault_tenant_id=key_vault_tenant_id,
    key_vault_client_id=key_vault_client_id,
    key_vault_client_secret=key_vault_client_secret):

        # --------------------------------------------------
        # SHORT CIRCUIT
        # --------------------------------------------------

        if smExists and repExists:
            logger.info("No deployment required. Assets already exist.")

        else:

            # --------------------------------------------------
            # DEPLOY SEMANTIC MODEL
            # --------------------------------------------------

            if not smExists:
                stage("Deploy Semantic Model")

                labs.deploy_semantic_model(
                    source_dataset=SOURCE_DATASET_NAME,
                    source_workspace=SOURCE_WORKSPACE_NAME,
                    target_dataset=TARGET_SEMANTICMODEL_NAME,
                    target_workspace=TARGET_WORKSPACE_NAME,
                    refresh_target_dataset=False,
                    overwrite=True
                )
                
                directlake.update_direct_lake_model_connection(
                    dataset=TARGET_SEMANTICMODEL_NAME,
                    workspace=TARGET_WORKSPACE_NAME,
                    source=LAKEHOUSE_NAME,
                    source_type="Lakehouse",
                    source_workspace=TARGET_WORKSPACE_NAME,
                    use_sql_endpoint=False
                )

            # --------------------------------------------------
            # CLONE REPORT
            # --------------------------------------------------

            if not repExists:
                stage("Clone Report")

                rep.clone_report(
                    report=SOURCE_REPORT_NAME,
                    cloned_report=SOURCE_REPORT_NAME,
                    workspace=SOURCE_WORKSPACE_NAME,
                    target_workspace=TARGET_WORKSPACE_NAME,
                    target_dataset=TARGET_SEMANTICMODEL_NAME,
                    target_dataset_workspace=TARGET_WORKSPACE_NAME
                )

                rep.report_rebind(
                    report=SOURCE_REPORT_NAME,
                    dataset=TARGET_SEMANTICMODEL_NAME,
                    report_workspace=TARGET_WORKSPACE_NAME,
                    dataset_workspace=TARGET_WORKSPACE_NAME
                )

        # --------------------------------------------------
        # FINAL REFRESH
        # --------------------------------------------------

        stage("Refresh Semantic Model")

        time.sleep(10)

        try:
            labs.refresh_semantic_model(
                dataset=TARGET_SEMANTICMODEL_NAME,
                workspace=TARGET_WORKSPACE_NAME
            )
        except Exception as e:
            logger.error(f"Semantic model refresh failed: {str(e)}")
            raise
                
    logger.info("Deployment completed successfully")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I missing here? how to update Direct Lake SM connection?&lt;/P&gt;</description>
    <pubDate>Wed, 22 Apr 2026 17:25:15 GMT</pubDate>
    <dc:creator>Kuladeep</dc:creator>
    <dc:date>2026-04-22T17:25:15Z</dc:date>
    <item>
      <title>Notebook with sempy_labs failed when executed in DataPipeline</title>
      <link>https://community.fabric.microsoft.com/t5/Pipelines/Notebook-with-sempy-labs-failed-when-executed-in-DataPipeline/m-p/5156040#M9365</link>
      <description>&lt;P&gt;Hello Fabric Community,&lt;/P&gt;&lt;P&gt;I’ve been struggling with the complex execution context in Fabric (p.s. &lt;A href="https://peerinsights.emono.dk/whos-calling" target="_blank" rel="noopener"&gt;Who's Calling?&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;I created a notebook to deploy a (template) Semantic Model from a central workspace to a target workspace using sempy_labs.labs.&lt;/P&gt;&lt;P&gt;When I execute this notebook using a user identity, &lt;STRONG&gt;it works&lt;/STRONG&gt; &lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt;&lt;/P&gt;&lt;P&gt;When I execute the notebook inside a pipeline with a connection (authenticated using a Service Principal), &lt;STRONG&gt;it fails&lt;/STRONG&gt; &lt;span class="lia-unicode-emoji" title=":cross_mark:"&gt;❌&lt;/span&gt; with the following error (though the SP has contributor access on both source and target WS):&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;FONT color="#FF0000"&gt;FabricHTTPException&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;403 Forbidden for URL: &lt;A href="https://api.fabric.microsoft.com/v1.0/myorg/groups/xxxxxxxx-yyyyy-zzzzz-000000/datasets" target="_blank" rel="noopener"&gt;https://api.fabric.microsoft.com/v1.0/myorg/groups/xxxxxxxx-yyyyy-zzzzz-000000/datasets&lt;/A&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;Headers: {'Content-Length': '0', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains', 'X-Frame-Options': 'deny', 'X-Content-Type-Options': 'nosniff', 'Access-Control-Expose-Headers': 'RequestId', 'RequestId': 'a9bd2bed-ff7b-4c1c-b28d-551727ebe685', 'Date': 'Mon, 20 Apr 2026 18:56:10 GMT'}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;When I execute the notebook inside a data pipeline &lt;STRONG&gt;without a connection&lt;/STRONG&gt;, it occasionally works, but mostly throws this error:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;FONT color="#FF0000"&gt;WorkspaceNotFoundException&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;Workspace 'xxxxxxxx-yyyyy-zzzzz-000000' not found.&lt;/FONT&gt;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;Below is the code:&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;import sempy_labs as labs
from sempy_labs import directlake
import sempy_labs.report as rep
import time
import logging
import sys
import os
import requests

# all the variables and parameters are collected and passed correctly (ignore them)

# Helper functions

def get_workspace_id(workspace_name: str | None):
    if not workspace_name:
        return None
    df = fabric.list_workspaces()
    row = df.loc[df["Name"] == workspace_name, "Id"]
    return row.iloc[0] if not row.empty else None

def get_item_id(workspace_id, item_name, item_type):
    df = fabric.list_items(workspace=workspace_id)
    row = df.loc[
        (df["Type"] == item_type) &amp;amp;
        (df["Display Name"] == item_name),
        "Id"
    ]
    return row.iloc[0] if not row.empty else None

def semantic_model_exists(workspace_id, dataset_name):
    return get_item_id(workspace_id, dataset_name, "SemanticModel") is not None


def report_exists(workspace_id, report_name):
    return get_item_id(workspace_id, report_name, "Report") is not None

def stage(name):
    logger.info(f"=== {name} ===")

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s | %(levelname)s | %(message)s",
    handlers=[logging.StreamHandler(sys.stdout)]
)

logger = logging.getLogger("deployment")

def main():

    stage("Resolve Context")

    target_workspace_id = workspaceId
    lakehouse_id = lakehouseId

    if not target_workspace_id:
        raise ValueError(f"Workspace not found: {TARGET_WORKSPACE_NAME}")

    if not lakehouse_id:
        raise ValueError(f"Lakehouse not found: {LAKEHOUSE_NAME}")

    stage("Check Existing Assets")

    sm_exists = semantic_model_exists(
        target_workspace_id,
        TARGET_SEMANTICMODEL_NAME
    )

    rep_exists = report_exists(
        target_workspace_id,
        SOURCE_REPORT_NAME
    )

    logger.info(f"Semantic model exists: {sm_exists}")
    logger.info(f"Report exists: {rep_exists}")

    # --------------------------------------------------
    # SHORT CIRCUIT
    # --------------------------------------------------

    if sm_exists and rep_exists:
        logger.info("Nothing to deploy")
    else:

        if not sm_exists:
            stage("Deploy Semantic Model")

            labs.deploy_semantic_model(
                source_dataset=SOURCE_DATASET_NAME,
                source_workspace=SOURCE_WORKSPACE_NAME,
                target_dataset=TARGET_SEMANTICMODEL_NAME,
                target_workspace=TARGET_WORKSPACE_NAME,
                refresh_target_dataset=False,
                overwrite=True
            )

            directlake.update_direct_lake_model_connection(
                dataset=TARGET_SEMANTICMODEL_NAME,
                workspace=TARGET_WORKSPACE_NAME,
                source=LAKEHOUSE_NAME,
                source_type="Lakehouse",
                source_workspace=TARGET_WORKSPACE_NAME,
                use_sql_endpoint=False
            )

        # --------------------------------------------------
        # CLONE REPORT
        # --------------------------------------------------

        if not rep_exists:
            stage("Clone Report")

            rep.clone_report(
                report=SOURCE_REPORT_NAME,
                cloned_report=SOURCE_REPORT_NAME,
                workspace=SOURCE_WORKSPACE_NAME,
                target_workspace=TARGET_WORKSPACE_NAME,
                target_dataset=TARGET_SEMANTICMODEL_NAME,
                target_dataset_workspace=TARGET_WORKSPACE_NAME
            )

            rep.report_rebind(
                report=SOURCE_REPORT_NAME,
                dataset=TARGET_SEMANTICMODEL_NAME,
                report_workspace=TARGET_WORKSPACE_NAME,
                dataset_workspace=TARGET_WORKSPACE_NAME
            )

    # --------------------------------------------------
    # FINAL REFRESH
    # --------------------------------------------------

    stage("Refresh Semantic Model")

    time.sleep(10)

    try:
        labs.refresh_semantic_model(
        dataset=TARGET_SEMANTICMODEL_NAME,
        workspace=TARGET_WORKSPACE_NAME
        )
    except Exception as e:
        raise


    logger.info("Deployment completed successfully")
​&lt;/LI-CODE&gt;&lt;P&gt;Can someone help me how can I achieve the deployment by the pipeline execution, preferably, using SP. Because my pipeline triggers via Fabric API from an external application using SP.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2026 15:33:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Pipelines/Notebook-with-sempy-labs-failed-when-executed-in-DataPipeline/m-p/5156040#M9365</guid>
      <dc:creator>Kuladeep</dc:creator>
      <dc:date>2026-04-22T15:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: Notebook with sempy_labs failed when executed in DataPipeline</title>
      <link>https://community.fabric.microsoft.com/t5/Pipelines/Notebook-with-sempy-labs-failed-when-executed-in-DataPipeline/m-p/5156078#M9366</link>
      <description>&lt;P&gt;I found an article from semantic-link-labs (&lt;A href="https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb" target="_blank" rel="noopener"&gt;semantic-link-labs/notebooks/Service Principal.ipynb at main · microsoft/semantic-link-labs · GitHub&lt;/A&gt;) and adjusted my function accordingly.&lt;BR /&gt;Everything works except the&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;directlake.update_direct_lake_model_connection() &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;with error:&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;FONT size="2" color="#FF0000"&gt;ConnectionException&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;FONT size="2" color="#FF0000"&gt;The specified Power BI workspace ('6e33da9d-a067-4519-a893-b9aa0d867d95') is not found. Technical Details: RootActivityId: 4b87e95d-5bd9-4418-87e4-a320b18fda4b Workspace: '6e33da9d-a067-4519-a893-b9aa0d867d95' at Microsoft.AnalysisServices.ConnectionInfo.ResolveHTTPConnectionProperties&lt;/FONT&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def main():

    stage("Resolve Context")

    targetWorkspaceId = workspaceId
    targetLakehouseId = lakehouseId

    if not targetWorkspaceId:
        raise ValueError(f"Workspace not found: {TARGET_WORKSPACE_NAME}")

    if not targetLakehouseId:
        raise ValueError(f"Lakehouse not found: {LAKEHOUSE_NAME}")

    stage("Check Existing Assets")

    smExists = semanticModelExists(
        targetWorkspaceId,
        TARGET_SEMANTICMODEL_NAME
    )

    repExists = reportExists(
        targetWorkspaceId,
        SOURCE_REPORT_NAME
    )

    logger.info(f"Semantic model exists: {smExists}")
    logger.info(f"Report exists: {repExists}")

    # --------------------------------------------------
    # AUTHENTICATION BLOCK (IMPORTANT)
    # --------------------------------------------------

    with labs.service_principal_authentication(
        key_vault_uri=key_vault_uri, 
    key_vault_tenant_id=key_vault_tenant_id,
    key_vault_client_id=key_vault_client_id,
    key_vault_client_secret=key_vault_client_secret):

        # --------------------------------------------------
        # SHORT CIRCUIT
        # --------------------------------------------------

        if smExists and repExists:
            logger.info("No deployment required. Assets already exist.")

        else:

            # --------------------------------------------------
            # DEPLOY SEMANTIC MODEL
            # --------------------------------------------------

            if not smExists:
                stage("Deploy Semantic Model")

                labs.deploy_semantic_model(
                    source_dataset=SOURCE_DATASET_NAME,
                    source_workspace=SOURCE_WORKSPACE_NAME,
                    target_dataset=TARGET_SEMANTICMODEL_NAME,
                    target_workspace=TARGET_WORKSPACE_NAME,
                    refresh_target_dataset=False,
                    overwrite=True
                )
                
                directlake.update_direct_lake_model_connection(
                    dataset=TARGET_SEMANTICMODEL_NAME,
                    workspace=TARGET_WORKSPACE_NAME,
                    source=LAKEHOUSE_NAME,
                    source_type="Lakehouse",
                    source_workspace=TARGET_WORKSPACE_NAME,
                    use_sql_endpoint=False
                )

            # --------------------------------------------------
            # CLONE REPORT
            # --------------------------------------------------

            if not repExists:
                stage("Clone Report")

                rep.clone_report(
                    report=SOURCE_REPORT_NAME,
                    cloned_report=SOURCE_REPORT_NAME,
                    workspace=SOURCE_WORKSPACE_NAME,
                    target_workspace=TARGET_WORKSPACE_NAME,
                    target_dataset=TARGET_SEMANTICMODEL_NAME,
                    target_dataset_workspace=TARGET_WORKSPACE_NAME
                )

                rep.report_rebind(
                    report=SOURCE_REPORT_NAME,
                    dataset=TARGET_SEMANTICMODEL_NAME,
                    report_workspace=TARGET_WORKSPACE_NAME,
                    dataset_workspace=TARGET_WORKSPACE_NAME
                )

        # --------------------------------------------------
        # FINAL REFRESH
        # --------------------------------------------------

        stage("Refresh Semantic Model")

        time.sleep(10)

        try:
            labs.refresh_semantic_model(
                dataset=TARGET_SEMANTICMODEL_NAME,
                workspace=TARGET_WORKSPACE_NAME
            )
        except Exception as e:
            logger.error(f"Semantic model refresh failed: {str(e)}")
            raise
                
    logger.info("Deployment completed successfully")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I missing here? how to update Direct Lake SM connection?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2026 17:25:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Pipelines/Notebook-with-sempy-labs-failed-when-executed-in-DataPipeline/m-p/5156078#M9366</guid>
      <dc:creator>Kuladeep</dc:creator>
      <dc:date>2026-04-22T17:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Notebook with sempy_labs failed when executed in DataPipeline</title>
      <link>https://community.fabric.microsoft.com/t5/Pipelines/Notebook-with-sempy-labs-failed-when-executed-in-DataPipeline/m-p/5156107#M9367</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1308737" data-lia-user-login="Kuladeep" class="lia-mention lia-mention-user"&gt;Kuladeep&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before confirming the exact cause, could you check a few things in your environment?&lt;/P&gt;&lt;P&gt;1. Capacity XMLA Endpoint&lt;/P&gt;&lt;P&gt;Go to Admin Portal → Capacity Settings → [your capacity] → XMLA Endpoint&lt;/P&gt;&lt;P&gt;Is it set to Read, Read/Write, or disabled?&lt;/P&gt;&lt;P&gt;update_direct_lake_model_connection uses XMLA internally — if it's not set to Read/Write, the Service Principal can't resolve the workspace and throws exactly that error.&lt;/P&gt;&lt;P&gt;2. Service Principal enabled in Tenant Settings&lt;/P&gt;&lt;P&gt;Go to Admin Portal → Tenant Settings → Developer Settings&lt;/P&gt;&lt;P&gt;Is "Allow service principals to use Power BI APIs" enabled? Does it apply to the whole organization or only to a specific Security Group? Is your SP included?&lt;/P&gt;&lt;P&gt;3. SP role in the TARGET workspace&lt;/P&gt;&lt;P&gt;In the destination workspace (6e33da9d...), what role does the Service Principal have assigned? It needs at least Member, ideally Admin.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If my comments helped solve your question, it would be great if you could like all comment and mark it as the accepted solution. It helps others with the same issue and also motivates me to keep contributing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot, I really appreciate it.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2026 19:27:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Pipelines/Notebook-with-sempy-labs-failed-when-executed-in-DataPipeline/m-p/5156107#M9367</guid>
      <dc:creator>arabalca</dc:creator>
      <dc:date>2026-04-22T19:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: Notebook with sempy_labs failed when executed in DataPipeline</title>
      <link>https://community.fabric.microsoft.com/t5/Pipelines/Notebook-with-sempy-labs-failed-when-executed-in-DataPipeline/m-p/5156258#M9368</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="781788" data-lia-user-login="arabalca" class="lia-mention lia-mention-user"&gt;arabalca&lt;/a&gt;,&lt;BR /&gt;Thanks for your reply.&lt;BR /&gt;&lt;BR /&gt;1. Yes, XMLA Endpoint is set to `&lt;STRONG&gt;Read Write&lt;/STRONG&gt;`&lt;/P&gt;&lt;P&gt;2. The Service principal settings enabled on tenant and the security group, which the SP is part of, is also added to the settings&lt;/P&gt;&lt;P&gt;3. The SP has &lt;STRONG&gt;Admin&lt;/STRONG&gt; level permissions on the WS&lt;BR /&gt;&lt;BR /&gt;Yet it fail.. Is there any other way to repoint S`M connection to new LH via API or notebookutils?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2026 06:43:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Pipelines/Notebook-with-sempy-labs-failed-when-executed-in-DataPipeline/m-p/5156258#M9368</guid>
      <dc:creator>Kuladeep</dc:creator>
      <dc:date>2026-04-23T06:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Notebook with sempy_labs failed when executed in DataPipeline</title>
      <link>https://community.fabric.microsoft.com/t5/Pipelines/Notebook-with-sempy-labs-failed-when-executed-in-DataPipeline/m-p/5156512#M9372</link>
      <description>&lt;P&gt;I have implemented a workaround function to bypass editing the XMLA endpoint (&lt;STRONG&gt;&lt;SPAN&gt;directlake.update_direct_lake_model_connection()&lt;/SPAN&gt;&lt;/STRONG&gt;) using a REST-based approach.&lt;BR /&gt;&lt;BR /&gt;Here is my function to update the direct lake connection&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def update_direct_lake_onelake_connection(
    dataset_name: str,
    workspace_name: str,
    lakehouse_name: str,
    lakehouse_workspace_name: str,
) -&amp;gt; None:
    """
    Patch the OneLake DFS URL in a Direct Lake semantic model's shared
    expressions to point to the correct target Lakehouse.

    Uses the Fabric REST API (getDefinition / updateDefinition) so that
    Service Principal authentication is honoured correctly — bypassing
    the XMLA endpoint where SP tokens are not forwarded by sempy_labs.

    Parameters
    ----------
    dataset_name             : Display name of the target semantic model.
    workspace_name           : Display name of the workspace containing the model.
    lakehouse_name           : Display name of the target lakehouse.
    lakehouse_workspace_name : Display name of the workspace containing the lakehouse.
    """
    logger.info("Resolving IDs for Direct Lake connection update...")

    workspace_id          = get_workspace_id(workspace_name)
    lakehouse_workspace_id = get_workspace_id(lakehouse_workspace_name)
    lakehouse_id          = get_lakehouse_id(lakehouse_workspace_id, lakehouse_name)
    dataset_id            = get_semantic_model_id(workspace_id, dataset_name)

    if not dataset_id:
        raise ValueError(f"Semantic model '{dataset_name}' not found in workspace '{workspace_name}'.")

    logger.info(f"  Workspace ID:           {workspace_id}")
    logger.info(f"  Lakehouse Workspace ID: {lakehouse_workspace_id}")
    logger.info(f"  Lakehouse ID:           {lakehouse_id}")
    logger.info(f"  Semantic Model ID:      {dataset_id}")

    # --------------------------------------------------
    # Get model definition (handles sync 200 and async 202)
    # --------------------------------------------------
    r = requests.post(
        f"{FABRIC_API_BASE}/workspaces/{workspace_id}/semanticModels/{dataset_id}/getDefinition",
        headers=HEADERS,
    )
    r.raise_for_status()

    if r.status_code == 202:
        poll_result = poll_operation(r.headers["Location"], "getDefinition")
        if "definition" in poll_result:
            parts = poll_result["definition"]["parts"]
        else:
            result_url = poll_result.get("resourceLocation") or r.headers["Location"] + "/result"
            result_r = requests.get(result_url, headers=HEADERS)
            result_r.raise_for_status()
            parts = result_r.json()["definition"]["parts"]
    else:
        parts = r.json()["definition"]["parts"]

    # --------------------------------------------------
    # Patch OneLake URL in all matching parts
    # --------------------------------------------------
    new_url = (
        f"https://onelake.dfs.fabric.microsoft.com/"
        f"{lakehouse_workspace_id}/{lakehouse_id}"
    )
    onelake_pattern = re.compile(
        r"https://onelake\.dfs\.fabric\.microsoft\.com/"
        r"[0-9a-fA-F\-]{36}/[0-9a-fA-F\-]{36}"
    )
    patched = False

    for part in parts:
        content = base64.b64decode(part["payload"]).decode("utf-8")

        if "onelake.dfs.fabric.microsoft.com" not in content.lower():
            continue

        updated = onelake_pattern.sub(new_url, content)

        if updated == content:
            logger.warning(
                f"Part '{part['path']}' contains OneLake URL but regex did not match — "
                f"inspect manually:\n{content}"
            )
            continue

        logger.info(f"  Patched part: {part['path']}")
        part["payload"] = base64.b64encode(updated.encode("utf-8")).decode("utf-8")
        patched = True

    if not patched:
        raise ValueError(
            f"No patchable OneLake URL found in model '{dataset_name}'. "
            "Verify this is a Direct Lake model."
        )

    # --------------------------------------------------
    # Push updated definition back (handles sync / async)
    # --------------------------------------------------
    r2 = requests.post(
        f"{FABRIC_API_BASE}/workspaces/{workspace_id}/semanticModels/{dataset_id}/updateDefinition",
        headers=HEADERS,
        json={"definition": {"parts": parts}},
    )
    r2.raise_for_status()

    if r2.status_code == 202:
        poll_operation(r2.headers["Location"], "updateDefinition")

    logger.info("Direct Lake OneLake connection updated successfully.")&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 23 Apr 2026 14:18:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Pipelines/Notebook-with-sempy-labs-failed-when-executed-in-DataPipeline/m-p/5156512#M9372</guid>
      <dc:creator>Kuladeep</dc:creator>
      <dc:date>2026-04-23T14:18:03Z</dc:date>
    </item>
  </channel>
</rss>

