From a4a14e951494a2fee015866cf29f833826e44d11 Mon Sep 17 00:00:00 2001 From: maxsibilla Date: Wed, 25 Sep 2024 15:13:54 -0400 Subject: [PATCH] Modifying get_sources_associated_entity to handle the casting of embedded metadata into json object --- src/schema/schema_neo4j_queries.py | 8 ++++++++ src/schema/schema_triggers.py | 13 ++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/schema/schema_neo4j_queries.py b/src/schema/schema_neo4j_queries.py index 2477cb4..8c60698 100644 --- a/src/schema/schema_neo4j_queries.py +++ b/src/schema/schema_neo4j_queries.py @@ -1,3 +1,5 @@ +import ast + from neo4j.exceptions import TransactionError import logging @@ -2142,4 +2144,10 @@ def get_sources_associated_entity(neo4j_driver, uuid, filter_out = None): # Convert the neo4j node into Python dict results = nodes_to_dicts(record[record_field_name]) + for result in results: + if 'metadata' in result and result['metadata'] != '{}': + result['metadata'] = ast.literal_eval(result['metadata']) + else: + result.pop('metadata', None) + return results diff --git a/src/schema/schema_triggers.py b/src/schema/schema_triggers.py index 1b54bbc..ed2baca 100644 --- a/src/schema/schema_triggers.py +++ b/src/schema/schema_triggers.py @@ -3536,12 +3536,8 @@ def set_dataset_sources(property_key, normalized_type, user_token, existing_data str: The target property key list: The list of sources associated with a dataset """ - sources = schema_neo4j_queries.get_sources_associated_entity(schema_manager.get_neo4j_driver_instance(), existing_data_dict['uuid']) - for source in sources: - if 'metadata' in source and source['metadata'] != '{}': - source['metadata'] = ast.literal_eval(source['metadata']) - else: - source.pop('metadata', None) + sources = schema_neo4j_queries.get_sources_associated_entity(schema_manager.get_neo4j_driver_instance(), + existing_data_dict['uuid']) return property_key, sources @@ -3569,11 +3565,6 @@ def set_sample_source(property_key, normalized_type, user_token, existing_data_d """ sources = schema_neo4j_queries.get_sources_associated_entity(schema_manager.get_neo4j_driver_instance(), existing_data_dict['uuid']) - for source in sources: - if 'metadata' in source and source['metadata'] != '{}': - source['metadata'] = ast.literal_eval(source['metadata']) - else: - source.pop('metadata', None) return property_key, sources[0]