Skip to content

Commit

Permalink
fix: issue when not resolving reference
Browse files Browse the repository at this point in the history
InvalidResourceException was created incorrectly, which caused a
TypeError.
  • Loading branch information
jsolaas committed Jan 30, 2025
1 parent a61a6ce commit 9dc1705
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/libecalc/presentation/yaml/mappers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
convert_rate_to_am3_per_hour,
convert_temperature_to_kelvin,
get_single_speed_chart_data,
resolve_reference,
resolve_model_reference,
)
from libecalc.presentation.yaml.resource import Resource, Resources
from libecalc.presentation.yaml.validation_errors import (
Expand Down Expand Up @@ -232,7 +232,7 @@ def _generic_from_design_point_compressor_chart_mapper(


def _resolve_and_validate_chart(compressor_chart_reference, input_models: dict[str, Any]) -> CompressorChart:
compressor_chart = resolve_reference(
compressor_chart = resolve_model_reference(
value=compressor_chart_reference,
references=input_models,
)
Expand All @@ -258,7 +258,7 @@ def _variable_speed_compressor_train_multiple_streams_and_pressures_stream_mappe
stream_type = stream_config.type
fluid_model_reference = stream_config.fluid_model
if fluid_model_reference is not None:
fluid_model = resolve_reference(value=fluid_model_reference, references=input_models)
fluid_model = resolve_model_reference(value=fluid_model_reference, references=input_models)
return MultipleStreamsAndPressureStream(
name=reference_name,
fluid_model=fluid_model,
Expand All @@ -277,7 +277,7 @@ def _variable_speed_compressor_train_multiple_streams_and_pressures_stage_mapper
input_models: dict[str, Any],
) -> MultipleStreamsCompressorStage:
compressor_chart_reference = stage_config.compressor_chart
compressor_chart = resolve_reference(value=compressor_chart_reference, references=input_models)
compressor_chart = resolve_model_reference(value=compressor_chart_reference, references=input_models)
inlet_temperature_kelvin = convert_temperature_to_kelvin(
[stage_config.inlet_temperature],
input_unit=Unit.CELSIUS,
Expand Down Expand Up @@ -534,11 +534,11 @@ def _turbine_mapper(model_config: YamlTurbine, input_models: dict[str, Any], res
def _compressor_with_turbine_mapper(
model_config: YamlCompressorWithTurbine, input_models: dict[str, Any], resources: Resources
) -> CompressorWithTurbine:
compressor_train_model = resolve_reference(
compressor_train_model = resolve_model_reference(
value=model_config.compressor_model,
references=input_models,
)
turbine_model = resolve_reference(
turbine_model = resolve_model_reference(
value=model_config.turbine_model,
references=input_models,
)
Expand Down
6 changes: 4 additions & 2 deletions src/libecalc/presentation/yaml/mappers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def is_reference(value: Any) -> bool:
ReferenceValue = TypeVar("ReferenceValue")


def resolve_reference(value: Any, references: dict[str, ReferenceValue]) -> ReferenceValue:
def resolve_model_reference(value: Any, references: dict[str, ReferenceValue]) -> ReferenceValue:
"""Check if value is a reference and return it.
If not a reference return the original value
If reference is invalid, raise InvalidReferenceException
Expand All @@ -58,7 +58,9 @@ def resolve_reference(value: Any, references: dict[str, ReferenceValue]) -> Refe

if value not in references:
available_references = ",\n".join(references.keys())
raise InvalidReferenceException(f"'{value}' not found. \n\nAvailable references:\n{available_references}")
raise InvalidReferenceException(
reference_type="model", reference=value, available_references=available_references
)

return references[value]

Expand Down

0 comments on commit 9dc1705

Please sign in to comment.