diff --git a/src/metldata/builtin_transformations/common/assumptions.py b/src/metldata/builtin_transformations/common/assumptions.py index 1d2ab1e..0d7dc6f 100644 --- a/src/metldata/builtin_transformations/common/assumptions.py +++ b/src/metldata/builtin_transformations/common/assumptions.py @@ -111,9 +111,11 @@ class in the provided `path_element`, depending on the type of the relation path def assert_object_path_required(json_schema: Mapping[str, Any], path: str) -> None: - """Ensures that a path exists and its components are marked as 'required' in the schemapack. - This validates that any transformation relying on that path can depend on its presence - in a datapack. + """Ensures that a given object path in a JSON schema is marked as required. + This validates that any transformation relying on that path can depend on its + presence in a datapack. + + If the path is an empty string, no validation is required. """ if not path: return diff --git a/src/metldata/builtin_transformations/infer_relations/data_transform.py b/src/metldata/builtin_transformations/infer_relations/data_transform.py index 7d2b088..695ee3d 100644 --- a/src/metldata/builtin_transformations/infer_relations/data_transform.py +++ b/src/metldata/builtin_transformations/infer_relations/data_transform.py @@ -65,7 +65,7 @@ def resolve_active_path_element( data: DataPack, source_resource_id: ResourceId, path_element: RelationPathElement, -) -> set[ResourceId] | frozenset[ResourceId]: +) -> frozenset[ResourceId]: """Resolve the given relation inference path element of active type for the given source resource. @@ -95,9 +95,9 @@ def resolve_active_path_element( raise EvitableTransformationError() target_resource_ids = source_resource.relations.get(path_element.property) if target_resource_ids is None: - target_resource_ids = set() + target_resource_ids = frozenset() elif isinstance(target_resource_ids, str): - target_resource_ids = {target_resource_ids} + target_resource_ids = frozenset({target_resource_ids}) return target_resource_ids @@ -106,7 +106,7 @@ def resolve_passive_path_element( data: DataPack, source_resource_id: ResourceId, path_element: RelationPathElement, -) -> set[ResourceId]: +) -> frozenset[ResourceId]: """Resolve the given relation inference path element of passive type for the given source resource. @@ -137,7 +137,7 @@ def resolve_passive_path_element( ) or source_resource_id == relation: target_resource_ids.add(candidate_resource_id) - return target_resource_ids + return frozenset(target_resource_ids) def resolve_path_element( @@ -145,7 +145,7 @@ def resolve_path_element( data: DataPack, source_resource_id: ResourceId, path_element: RelationPathElement, -) -> set[ResourceId] | frozenset[ResourceId]: +) -> frozenset[ResourceId]: """Resolve the given relation inference path element for the given source resource. Args: @@ -171,7 +171,7 @@ def resolve_path_element( def resolve_path( *, data: DataPack, source_resource_id: ResourceId, path: RelationPath -) -> set[ResourceId]: +) -> frozenset[ResourceId]: """Resolve the given relation inference path for the given source resource. Args: @@ -197,7 +197,7 @@ def resolve_path( ) } - return resource_ids + return frozenset(resource_ids) def add_inferred_relations( @@ -220,9 +220,7 @@ def add_inferred_relations( update={ "relations": { **host_resource.relations, - instruction.new_property: frozenset( - target_resource_ids - ), # freeze inferred relations for datapack data type compatibility + instruction.new_property: target_resource_ids, } } )