Skip to content

Commit

Permalink
removed all arg from get_identifying_paths in portal_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed May 27, 2024
1 parent 141a48a commit ab88d6a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
7 changes: 2 additions & 5 deletions dcicutils/portal_object_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,12 @@ def diff_deleting(value: Any) -> object: # noqa
return diffs

@lru_cache(maxsize=1)
def _get_identifying_paths(self, all: bool = True,
ref_lookup_strategy: Optional[Callable] = None) -> Optional[List[str]]:
def _get_identifying_paths(self, ref_lookup_strategy: Optional[Callable] = None) -> Optional[List[str]]:
if not self._portal and (uuid := self.uuid):
if all is True and (type := self.type):
return [f"/{type}/{uuid}", f"/{uuid}"]
return [f"/{uuid}"]
# Migrating to and unifying this in portal_utils.Portal.get_identifying_paths (2024-05-26).
return self._portal.get_identifying_paths(self._data,
portal_type=self.schema, all=all,
portal_type=self.schema,
lookup_strategy=ref_lookup_strategy) if self._portal else None

def _normalized_refs(self, refs: List[dict]) -> Tuple[PortalObject, int]:
Expand Down
8 changes: 2 additions & 6 deletions dcicutils/portal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +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,
all: bool = True, lookup_strategy: Optional[Union[Callable, bool]] = None) -> List[str]:
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
and identifier based paths and defavors aliases based paths (ala self.get_identifying_property_names);
Expand Down Expand Up @@ -467,15 +467,11 @@ 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.
#
if all is True:
results.append(f"/{portal_type}/{identifying_value}")
results.append(f"/{identifying_value}")
elif isinstance(identifying_value, list):
for identifying_value_item in identifying_value:
if identifying_value_item:
results.append(f"/{portal_type}/{identifying_value_item}")
if all is True:
results.append(f"/{identifying_value_item}")
else:
lookup_options = Portal.LOOKUP_UNDEFINED
if schema := self.get_schema(portal_type):
Expand Down Expand Up @@ -542,7 +538,7 @@ def get_identifying_property_names(self, schema: Union[str, dict],
@staticmethod
def _lookup_strategy(portal: Portal, type_name: str, schema: dict, value: str) -> (int, Optional[str]):
#
# Note this slight odd situation WRT object lookups by submitted_id and accession:
# Note this slightly odd situation WRT object lookups by submitted_id and accession:
# -----------------------------+-----------------------------------------------+---------------+
# PATH | EXAMPLE | LOOKUP RESULT |
# -----------------------------+-----------------------------------------------+---------------+
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.8.6.1b7"
version = "8.8.6.1b8"
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down
10 changes: 4 additions & 6 deletions test/test_portal_object_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,7 @@ def test_compare():
assert portal_object.types == ["IngestionSubmission", "Item"]
assert not portal_object.schema
assert not portal_object.identifying_properties
assert portal_object._get_identifying_paths() == [f"/{TEST_OBJECT_DATABASE_JSON['@type'][0]}/{TEST_OBJECT_UUID}",
f"/{TEST_OBJECT_UUID}"]
assert portal_object._get_identifying_paths() == [f"/{TEST_OBJECT_UUID}"]
assert portal_object.compare(TEST_OBJECT_DATABASE_JSON) == ({}, 0)

portal_object_copy = portal_object.copy()
Expand All @@ -628,10 +627,9 @@ def test_compare():
assert portal_object_found.schema == TEST_OBJECT_SCHEMA_JSON
assert portal_object_found.identifying_properties == ["uuid", "aliases"]
assert portal_object_found._get_identifying_paths() == (
[f"/{TEST_OBJECT_DATABASE_JSON['@type'][0]}/{TEST_OBJECT_UUID}",
f"/{TEST_OBJECT_UUID}",
"/IngestionSubmission/foo", "/foo",
"/IngestionSubmission/bar", "/bar"])
[f"/{TEST_OBJECT_UUID}",
"/IngestionSubmission/foo",
"/IngestionSubmission/bar"])

portal_object_copy = portal_object.copy()
portal_object_copy.data["xyzzy"] = 123
Expand Down

0 comments on commit ab88d6a

Please sign in to comment.