From 174a83f3b59aa2bda84b985372a71973bce85204 Mon Sep 17 00:00:00 2001 From: David Michaels Date: Tue, 28 May 2024 07:16:32 -0400 Subject: [PATCH] update to portal_utils/get_identifying_path --- dcicutils/portal_utils.py | 11 +++++++++-- pyproject.toml | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dcicutils/portal_utils.py b/dcicutils/portal_utils.py index f93b0250b..005eb400a 100644 --- a/dcicutils/portal_utils.py +++ b/dcicutils/portal_utils.py @@ -407,6 +407,7 @@ def get_schema_subtype_names(self, type_name: str) -> List[str]: @function_cache(maxsize=100, serialize_key=True) def get_identifying_paths(self, portal_object: dict, portal_type: Optional[Union[str, dict]] = None, + first_only: bool = False, lookup_strategy: Optional[Union[Callable, bool]] = None) -> List[str]: """ Returns the list of the identifying Portal (URL) paths for the given Portal object. Favors any uuid @@ -467,7 +468,10 @@ def is_lookup_subtypes(lookup_options: int) -> bool: # noqa # And note the disction of just using /{uuid} here rather than /{type}/{uuid} as in the else # statement below is not really necessary; just here for emphasis that this is all that's needed. # - results.append(f"/{identifying_value}") + if first_only is True: + results.append(f"/{portal_type}/{identifying_value}") + else: + results.append(f"/{identifying_value}") elif isinstance(identifying_value, list): for identifying_value_item in identifying_value: if identifying_value_item: @@ -497,12 +501,15 @@ def is_lookup_subtypes(lookup_options: int) -> bool: # noqa if is_lookup_subtypes(lookup_options): for subtype_name in self.get_schema_subtype_names(portal_type): results.append(f"/{subtype_name}/{identifying_value}") + if (first_only is True) and results: + return results return results @function_cache(maxsize=100, serialize_key=True) def get_identifying_path(self, portal_object: dict, portal_type: Optional[Union[str, dict]] = None, lookup_strategy: Optional[Union[Callable, bool]] = None) -> Optional[str]: - if identifying_paths := self.get_identifying_paths(portal_object, portal_type, lookup_strategy): + if identifying_paths := self.get_identifying_paths(portal_object, portal_type, first_only=True, + lookup_strategy=lookup_strategy): return identifying_paths[0] return None diff --git a/pyproject.toml b/pyproject.toml index e0391f98a..c3c6bb584 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dcicutils" -version = "8.8.6.1b10" +version = "8.8.6.1b11" description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources" authors = ["4DN-DCIC Team "] license = "MIT"