From bbb75b80744cc73832ce06612513870afc62fe09 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Mon, 11 Aug 2025 15:09:31 -0400 Subject: [PATCH] Remove unnecessary warning log on superclass --- src/app.py | 4 +- src/schema/schema_manager.py | 71 ++++++++++++++++++------------ src/schema/schema_neo4j_queries.py | 4 +- 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/src/app.py b/src/app.py index 99ef704e..36bff7ab 100644 --- a/src/app.py +++ b/src/app.py @@ -4538,7 +4538,7 @@ def _get_entity_visibility(normalized_entity_type, entity_dict): return entity_visibility -''' +""" Retrieve the organ, donor, or sample metadata information associated with a Dataset, based up the user's authorization to access the Dataset. @@ -4561,7 +4561,7 @@ def _get_entity_visibility(normalized_entity_type, entity_dict): ------- list A dictionary containing the metadata properties the Dataset associated data. -''' +""" def _get_dataset_associated_metadata(dataset_dict, dataset_visibility, valid_user_token, request, associated_data: str): # Confirm the associated data requested is supported by this method. diff --git a/src/schema/schema_manager.py b/src/schema/schema_manager.py index 10ffa360..faa583d2 100644 --- a/src/schema/schema_manager.py +++ b/src/schema/schema_manager.py @@ -192,7 +192,7 @@ def get_all_entity_types(): """ -Get the superclass (if defined) of the given entity class +Get the optional superclass (if defined) of the given entity class Parameters ---------- @@ -209,32 +209,40 @@ def get_entity_superclass(normalized_entity_class): all_entity_types = get_all_entity_types() - if normalized_entity_class in all_entity_types: - if 'superclass' in _schema['ENTITIES'][normalized_entity_class]: - normalized_superclass = normalize_entity_type(_schema['ENTITIES'][normalized_entity_class]['superclass']) + if normalized_entity_class not in all_entity_types: + msg = f"Unrecognized value of 'normalized_entity_class': {normalized_entity_class}" + logger.error(msg) + raise ValueError(msg) - if normalized_superclass not in all_entity_types: - msg = f"Invalid 'superclass' value defined for {normalized_entity_class}: {normalized_superclass}" - logger.error(msg) - raise ValueError(msg) - else: - # Since the 'superclass' property is optional, we just log the warning message, no need to bubble up - msg = f"The 'superclass' property is not defined for entity class: {normalized_entity_class}" - logger.warning(msg) + if 'superclass' in _schema['ENTITIES'][normalized_entity_class]: + normalized_superclass = normalize_entity_type(_schema['ENTITIES'][normalized_entity_class]['superclass']) + + # Additional check to ensure no schema yaml mistake + if normalized_superclass not in all_entity_types: + msg = f"Invalid 'superclass' value defined for {normalized_entity_class}: {normalized_superclass}" + logger.error(msg) + raise ValueError(msg) return normalized_superclass -def entity_type_instanceof(entity_type: str, entity_class: str) -> bool: - """ - Determine if the Entity type with 'entity_type' is an instance of 'entity_class'. - Use this function if you already have the Entity type. Use entity_instanceof(uuid, class) - if you just have the Entity uuid. +""" +Determine if the Entity type with 'entity_type' is an instance of 'entity_class'. +Use this function if you already have the Entity type. Use `entity_instanceof(uuid, class)` +if you just have the Entity uuid. - :param entity_type: from Entity - :param entity_class: found in .yaml file - :return: True or False - """ +Parameters +---------- +entity_type : str + The superclass +entity_class : str + The subclass + +Returns +------- +bool +""" +def entity_type_instanceof(entity_type: str, entity_class: str) -> bool: if entity_type is None: return False @@ -247,14 +255,21 @@ def entity_type_instanceof(entity_type: str, entity_class: str) -> bool: return False -def entity_instanceof(entity_uuid: str, entity_class: str) -> bool: - """ - Determine if the Entity with 'entity_uuid' is an instance of 'entity_class'. +""" +Determine if the Entity with 'entity_uuid' is an instance of 'entity_class'. - :param entity_uuid: from Entity - :param entity_class: found in .yaml file - :return: True or False - """ +Parameters +---------- +entity_uuid : str + The uuid of the given entity +entity_class : str + The superclass + +Returns +------- +bool +""" +def entity_instanceof(entity_uuid: str, entity_class: str) -> bool: entity_type: str =\ schema_neo4j_queries.get_entity_type(get_neo4j_driver_instance(), entity_uuid.strip()) return entity_type_instanceof(entity_type, entity_class) diff --git a/src/schema/schema_neo4j_queries.py b/src/schema/schema_neo4j_queries.py index bbff230e..9d6e28d4 100644 --- a/src/schema/schema_neo4j_queries.py +++ b/src/schema/schema_neo4j_queries.py @@ -21,10 +21,10 @@ The neo4j database connection pool entity_type : str One of the normalized entity types: Dataset, Collection, Sample, Donor -superclass : str - The normalized entity superclass type if defined, None by default entity_data_dict : dict The target Entity node to be created +superclass : str + The normalized entity superclass type if defined, None by default Returns -------