diff --git a/.changes/unreleased/fixed-20260111-145147.yaml b/.changes/unreleased/fixed-20260111-145147.yaml new file mode 100644 index 00000000..b068c71c --- /dev/null +++ b/.changes/unreleased/fixed-20260111-145147.yaml @@ -0,0 +1,6 @@ +kind: fixed +body: Add ‘properties’ field to the item metadata list to eliminate unnecessary calls to the getItemDefinition API +time: 2026-01-11T14:51:47.974991712Z +custom: + Author: aviatco + AuthorLink: https://github.com/aviatco diff --git a/src/fabric_cli/commands/fs/fab_fs_get.py b/src/fabric_cli/commands/fs/fab_fs_get.py index 6712036f..6487458e 100644 --- a/src/fabric_cli/commands/fs/fab_fs_get.py +++ b/src/fabric_cli/commands/fs/fab_fs_get.py @@ -35,6 +35,7 @@ VirtualWorkspaceItem, Workspace, ) +from fabric_cli.utils import fab_cmd_get_utils as get_utils from fabric_cli.utils import fab_item_util, fab_ui, fab_util @@ -98,7 +99,7 @@ def _get_virtual_item(virtual_item: VirtualItem, args: Namespace) -> None: def _validate_sensitivity_label_warning(args: Namespace, item: Item) -> bool: # refactor to make the condition for get item with definition in one place - if args.query and args.query in fab_constant.ITEM_METADATA_PROPERTIES: + if args.query and get_utils.is_metadata_property_query(args.query): return True try: diff --git a/src/fabric_cli/commands/fs/get/fab_fs_get_item.py b/src/fabric_cli/commands/fs/get/fab_fs_get_item.py index a5283f18..20a8eb28 100644 --- a/src/fabric_cli/commands/fs/get/fab_fs_get_item.py +++ b/src/fabric_cli/commands/fs/get/fab_fs_get_item.py @@ -7,7 +7,6 @@ from fabric_cli.client import fab_api_item as item_api from fabric_cli.client import fab_api_jobs as jobs_api -from fabric_cli.core import fab_constant from fabric_cli.core.fab_types import ItemType from fabric_cli.core.hiearchy.fab_hiearchy import Item from fabric_cli.utils import fab_cmd_get_utils as utils_get @@ -22,7 +21,7 @@ def exec( ) -> dict: # If no payload query, no need to obtain definition obtain_definition = True - if args.query and args.query in fab_constant.ITEM_METADATA_PROPERTIES: + if args.query and utils_get.is_metadata_property_query(args.query): obtain_definition = False item_def = item_utils.get_item_with_definition( diff --git a/src/fabric_cli/core/fab_constant.py b/src/fabric_cli/core/fab_constant.py index d979b241..51ef0e75 100644 --- a/src/fabric_cli/core/fab_constant.py +++ b/src/fabric_cli/core/fab_constant.py @@ -324,6 +324,7 @@ "description", "workspaceId", "folderId", + "properties", } # Item set constants diff --git a/src/fabric_cli/utils/fab_cmd_get_utils.py b/src/fabric_cli/utils/fab_cmd_get_utils.py index 989b36bc..4d69ad98 100644 --- a/src/fabric_cli/utils/fab_cmd_get_utils.py +++ b/src/fabric_cli/utils/fab_cmd_get_utils.py @@ -9,10 +9,33 @@ from fabric_cli.client import fab_api_mirroring as mirroring_api from fabric_cli.utils import fab_jmespath as utils_jmespath from fabric_cli.utils import fab_storage as utils_storage -from fabric_cli.utils import fab_ui from fabric_cli.utils import fab_ui as utils_ui +def is_metadata_property_query(query: str) -> bool: + """ + Check if the query is for a metadata property or nested sub-property. + + Examples: + - "properties" -> True (exact match) + - "properties.connectionString" -> True (nested property) + - "id" -> True (exact match) + - "someOtherField" -> False (not a metadata property) + + Args: + query: The query string to check (assumed to be non-empty) + + Returns: + bool: True if query matches a metadata property or its nested properties + """ + from fabric_cli.core import fab_constant + + # Extract root property and check if it's a valid metadata property + # This handles both exact matches and nested properties in one step + root_property = query.split('.')[0] + return root_property in fab_constant.ITEM_METADATA_PROPERTIES + + def query_and_export( data: Any, args: Namespace, file_name: str, verbose: bool = True ) -> None: diff --git a/tests/test_commands/test_get.py b/tests/test_commands/test_get.py index ec5bb801..16ed083c 100644 --- a/tests/test_commands/test_get.py +++ b/tests/test_commands/test_get.py @@ -355,6 +355,26 @@ def test_get_folder_success( # endregion + def test_metadata_property_query_validation(self): + """Test the enhanced metadata property validation for nested properties.""" + from fabric_cli.utils.fab_cmd_get_utils import is_metadata_property_query + + # Test exact matches + assert is_metadata_property_query("properties") is True + assert is_metadata_property_query("id") is True + assert is_metadata_property_query("displayName") is True + assert is_metadata_property_query("description") is True + + # Test nested properties - the key enhancement + assert is_metadata_property_query("properties.connectionString") is True + assert is_metadata_property_query("properties.nested.value") is True + assert is_metadata_property_query("displayName.localized") is True + + # Test invalid properties + assert is_metadata_property_query("someField") is False + assert is_metadata_property_query("definition") is False + assert is_metadata_property_query("definition.content") is False + # region Helper Methods def get(path, output=None, query=None, deep_traversal=False, force=False):