microsoft / semantic-link-labs

Early access to new features for Microsoft Fabric's Semantic Link.
MIT License
177 stars 37 forks source link

create_model_bpa_semantic_model() issues error #290

Open lhammer100 opened 2 days ago

lhammer100 commented 2 days ago

I'm running pieces of the code from the "Best Practices Analyzer Report". The notebook is attached to a lake house and a relevant workspace is coded. After running labs.run_model_bpa_bulk(workspace) successfully, the call to labs.create_model_bpa_semantic_model() fails.

I have tried different variations, but they all fail with the same error message. See below.

It could be related to the call to create_blank_semantic_model(), were the json defining the blank semantic model includes setting languate and collation, but I'm not fully sure.

The following is the full error message:

File /nfs4/pyenv-d52b6d10-eab0-483c-9336-890d5e837aba/lib/python3.11/site-packages/sempy_labs/_model_bpa_bulk.py:241, in create_model_bpa_semantic_model(dataset, lakehouse, lakehouse_workspace)
    238 expr = get_shared_expression(lakehouse=lakehouse, workspace=lakehouse_workspace)
    240 # Create blank model
--> 241 create_blank_semantic_model(
    242     dataset=dataset, workspace=lakehouse_workspace, overwrite=True
    243 )
    245 @retry(
    246     sleep_time=1,
    247     timeout_error_message=f"{icons.red_dot} Function timed out after 1 minute",
    248 )
    249 def dyn_connect():
    250     with connect_semantic_model(
    251         dataset=dataset, readonly=True, workspace=lakehouse_workspace
    252     ) as tom:

File /nfs4/pyenv-d52b6d10-eab0-483c-9336-890d5e837aba/lib/python3.11/site-packages/sempy_labs/_generate_semantic_model.py:92, in create_blank_semantic_model(dataset, compatibility_level, workspace, overwrite)
     53     raise ValueError(
     54         f"{icons.red_dot} Compatiblity level must be at least {min_compat}."
     55     )
     57 tmsl = f"""
     58 {{
     59     "createOrReplace": {{
   (...)
     89 }}
     90 """
---> 92 fabric.execute_tmsl(script=tmsl, workspace=workspace)
     94 return print(
     95     f"{icons.green_dot} The '{dataset}' semantic model was created within the '{workspace}' workspace."
     96 )

File /nfs4/pyenv-d52b6d10-eab0-483c-9336-890d5e837aba/lib/python3.11/site-packages/sempy/_utils/_log.py:348, in mds_log.<locals>.get_wrapper.<locals>.log_decorator_wrapper(*args, **kwargs)
    345 start_time = time.perf_counter()
    347 try:
--> 348     result = func(*args, **kwargs)
    350     # The invocation for get_message_dict moves after the function
    351     # so it can access the state after the method call
    352     message.update(extractor.get_completion_message_dict(result, arg_dict))

File /nfs4/pyenv-d52b6d10-eab0-483c-9336-890d5e837aba/lib/python3.11/site-packages/sempy/fabric/_flat.py:49, in execute_tmsl(script, refresh_tom_cache, workspace)
     46     script = json.dumps(script)
     48 workspace_client = _get_or_create_workspace_client(workspace)
---> 49 workspace_client.execute_tmsl(script)
     51 if refresh_tom_cache:
     52     workspace_client.refresh_tom_cache()

File /nfs4/pyenv-d52b6d10-eab0-483c-9336-890d5e837aba/lib/python3.11/site-packages/sempy/fabric/_client/_workspace_client.py:369, in WorkspaceClient.execute_tmsl(self, script)
    365     msg = "\n".join(errors)
    367     if "was routed to wrong node by the Power BI request router. This is usually caused by intermittent issues. Please try again." not in msg \
    368        or retry == max_retries:
--> 369         raise RuntimeError(msg)
    371     time.sleep(retry * retry)
    372 else:
    373     # no errors, stop retry

RuntimeError: Error -1052639197: Culture and Collation properties of the Model object may be changed only before any other object has been created.

Technical Details:
RootActivityId: 744debad-837c-4a49-bf69-f49ae5d39d1b
Date (UTC): 11/19/2024 10:45:03 AM
m-kovalsky commented 2 days ago

Thanks. Made a fix for this to be in the next release.

Madalina128 commented 2 hours ago

Hi,

I've also tested the code from the "Best Practices Analyzer Report" and I got a similar error (not sure if it's related to this bug or not) when I tried to run create_model_bpa_semantic_model().

Could you please help with this issue?

Thank you!


AttributeError Traceback (most recent call last) Cell In[16], line 1 ----> 1 labs.create_model_bpa_semantic_model()

File ~/cluster-env/clonedenv/lib/python3.10/site-packages/sempy/_utils/_log.py:348, in mds_log..get_wrapper..log_decorator_wrapper(*args, *kwargs) 345 start_time = time.perf_counter() 347 try: --> 348 result = func(args, **kwargs) 350 # The invocation for get_message_dict moves after the function 351 # so it can access the state after the method call 352 message.update(extractor.get_completion_message_dict(result, arg_dict))

File ~/cluster-env/clonedenv/lib/python3.10/site-packages/sempy_labs/_model_bpa_bulk.py:238, in create_model_bpa_semantic_model(dataset, lakehouse, lakehouse_workspace) 233 lakehouse = resolve_lakehouse_name( 234 lakehouse_id=lakehouse_id, workspace=lakehouse_workspace 235 ) 237 # Generate the shared expression based on the lakehouse and lakehouse workspace --> 238 expr = get_shared_expression(lakehouse=lakehouse, workspace=lakehouse_workspace) 240 # Create blank model 241 create_blank_semantic_model( 242 dataset=dataset, workspace=lakehouse_workspace, overwrite=True 243 )

File ~/cluster-env/clonedenv/lib/python3.10/site-packages/sempy_labs/directlake/_get_shared_expression.py:35, in get_shared_expression(lakehouse, workspace) 32 lakehouse_id = fabric.get_lakehouse_id() 33 lakehouse = resolve_lakehouse_name(lakehouse_id, workspace) ---> 35 dfL = list_lakehouses(workspace=workspace) 36 lakeDetail = dfL[dfL["Lakehouse Name"] == lakehouse] 38 sqlEPCS = lakeDetail["SQL Endpoint Connection String"].iloc[0]

File ~/cluster-env/clonedenv/lib/python3.10/site-packages/sempy_labs/_list_functions.py:699, in list_lakehouses(workspace) 690 prop = v.get("properties", {}) 691 sqlEPProp = prop.get("sqlEndpointProperties", {}) 693 new_data = { 694 "Lakehouse Name": v.get("displayName"), 695 "Lakehouse ID": v.get("id"), 696 "Description": v.get("description"), 697 "OneLake Tables Path": prop.get("oneLakeTablesPath"), 698 "OneLake Files Path": prop.get("oneLakeFilesPath"), --> 699 "SQL Endpoint Connection String": sqlEPProp.get("connectionString"), 700 "SQL Endpoint ID": sqlEPProp.get("id"), 701 "SQL Endpoint Provisioning Status": sqlEPProp.get("provisioningStatus"), 702 } 703 df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True) 705 return df

AttributeError: 'NoneType' object has no attribute 'get'