From 652f1893c5c5d2c70d1d62b99884739c280158c7 Mon Sep 17 00:00:00 2001 From: Alexander Korn Date: Tue, 5 May 2026 14:38:27 +0200 Subject: [PATCH 1/3] Add fix_isavailable_in_mdx: set IsAvailableInMDX=False on hidden columns --- .../semantic_model/_Fix_IsAvailableInMdx.py | 43 +++++++++++++++++++ src/sempy_labs/semantic_model/__init__.py | 3 ++ 2 files changed, 46 insertions(+) create mode 100644 src/sempy_labs/semantic_model/_Fix_IsAvailableInMdx.py diff --git a/src/sempy_labs/semantic_model/_Fix_IsAvailableInMdx.py b/src/sempy_labs/semantic_model/_Fix_IsAvailableInMdx.py new file mode 100644 index 000000000..0bab07b0d --- /dev/null +++ b/src/sempy_labs/semantic_model/_Fix_IsAvailableInMdx.py @@ -0,0 +1,43 @@ +# Fix IsAvailableInMDX — standalone BPA fixer. +# Sets IsAvailableInMDX to False on non-attribute columns. + +from typing import Optional +from uuid import UUID + + +def fix_isavailable_in_mdx( + dataset: str, + workspace: Optional[str | UUID] = None, + scan_only: bool = False, +): + """ + Sets IsAvailableInMDX to False on columns where it is True. + + Parameters + ---------- + dataset : str + Name of the semantic model. + workspace : str | uuid.UUID, default=None + The Fabric workspace name or ID. + scan_only : bool, default=False + If True, only reports what would be fixed without making changes. + """ + from sempy_labs.tom import connect_semantic_model + + fixed = 0 + with connect_semantic_model(dataset=dataset, readonly=scan_only, workspace=workspace) as tom: + for table in tom.model.Tables: + for col in table.Columns: + if getattr(col, "IsAvailableInMDX", False): + if scan_only: + print(f" Would fix: '{table.Name}'[{col.Name}] IsAvailableInMDX → False") + else: + col.IsAvailableInMDX = False + print(f" Fixed: '{table.Name}'[{col.Name}] IsAvailableInMDX → False") + fixed += 1 + if not scan_only and fixed > 0: + tom.model.SaveChanges() + + action = "Would fix" if scan_only else "Fixed" + print(f" {action} {fixed} column(s).") + return fixed diff --git a/src/sempy_labs/semantic_model/__init__.py b/src/sempy_labs/semantic_model/__init__.py index 7c117f392..ae5769c6e 100644 --- a/src/sempy_labs/semantic_model/__init__.py +++ b/src/sempy_labs/semantic_model/__init__.py @@ -13,3 +13,6 @@ "make_discoverable", "enable_query_caching", ] + +from ._Fix_IsAvailableInMdx import fix_isavailable_in_mdx +__all__ += ["fix_isavailable_in_mdx"] From 19418ea04be38b78f88ea980d8833fc7df7cb774 Mon Sep 17 00:00:00 2001 From: Alexander Korn Date: Tue, 5 May 2026 15:02:34 +0200 Subject: [PATCH 2/3] Address Copilot review: mechanical fixes (drop SaveChanges, add @log, lint, init imports) --- src/sempy_labs/semantic_model/_Fix_IsAvailableInMdx.py | 4 ++-- src/sempy_labs/semantic_model/__init__.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sempy_labs/semantic_model/_Fix_IsAvailableInMdx.py b/src/sempy_labs/semantic_model/_Fix_IsAvailableInMdx.py index 0bab07b0d..5cddb9219 100644 --- a/src/sempy_labs/semantic_model/_Fix_IsAvailableInMdx.py +++ b/src/sempy_labs/semantic_model/_Fix_IsAvailableInMdx.py @@ -3,8 +3,10 @@ from typing import Optional from uuid import UUID +from sempy._utils._log import log +@log def fix_isavailable_in_mdx( dataset: str, workspace: Optional[str | UUID] = None, @@ -35,8 +37,6 @@ def fix_isavailable_in_mdx( col.IsAvailableInMDX = False print(f" Fixed: '{table.Name}'[{col.Name}] IsAvailableInMDX → False") fixed += 1 - if not scan_only and fixed > 0: - tom.model.SaveChanges() action = "Would fix" if scan_only else "Fixed" print(f" {action} {fixed} column(s).") diff --git a/src/sempy_labs/semantic_model/__init__.py b/src/sempy_labs/semantic_model/__init__.py index ae5769c6e..39708093c 100644 --- a/src/sempy_labs/semantic_model/__init__.py +++ b/src/sempy_labs/semantic_model/__init__.py @@ -6,13 +6,12 @@ from ._caching import ( enable_query_caching, ) +from ._Fix_IsAvailableInMdx import fix_isavailable_in_mdx __all__ = [ "approved_for_copilot", "set_endorsement", "make_discoverable", "enable_query_caching", + "fix_isavailable_in_mdx", ] - -from ._Fix_IsAvailableInMdx import fix_isavailable_in_mdx -__all__ += ["fix_isavailable_in_mdx"] From 5a2047f809ee2e327aef06f91a7ccaa0fbe3a926 Mon Sep 17 00:00:00 2001 From: Alexander Korn Date: Tue, 5 May 2026 15:29:41 +0200 Subject: [PATCH 3/3] Address Copilot review (wave 2): API/docs/safety fixes --- .../semantic_model/_Fix_IsAvailableInMdx.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/sempy_labs/semantic_model/_Fix_IsAvailableInMdx.py b/src/sempy_labs/semantic_model/_Fix_IsAvailableInMdx.py index 5cddb9219..944121971 100644 --- a/src/sempy_labs/semantic_model/_Fix_IsAvailableInMdx.py +++ b/src/sempy_labs/semantic_model/_Fix_IsAvailableInMdx.py @@ -8,21 +8,26 @@ @log def fix_isavailable_in_mdx( - dataset: str, + dataset: str | UUID, workspace: Optional[str | UUID] = None, scan_only: bool = False, -): +) -> int: """ Sets IsAvailableInMDX to False on columns where it is True. Parameters ---------- - dataset : str - Name of the semantic model. + dataset : str | UUID + Name or ID of the semantic model. workspace : str | uuid.UUID, default=None The Fabric workspace name or ID. scan_only : bool, default=False If True, only reports what would be fixed without making changes. + + Returns + ------- + int + Number of items fixed. """ from sempy_labs.tom import connect_semantic_model