Skip to content

Commit

Permalink
fix: missing parameter type error message
Browse files Browse the repository at this point in the history
  • Loading branch information
arjendev committed Oct 3, 2024
1 parent 3462ff1 commit cce6773
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,32 @@ def evaluate(self, expression: str, state: PipelineRunState) -> str:
expression = missing_parameter_match.group(2)
property_name = missing_parameter_match.group(4)

if expression.startswith("pipeline().parameters"):
if (
f"pipeline().parameters.{property_name}" in expression
and not state.contains_parameter_with_type_and_name(RunParameterType.Pipeline, property_name)
):
raise ParameterNotFoundError(RunParameterType.Pipeline, property_name) from e
elif expression.startswith("pipeline().globalParameters"):
elif (
f"pipeline().globalParameters.{property_name}" in expression
and not state.contains_parameter_with_type_and_name(RunParameterType.Global, property_name)
):
raise ParameterNotFoundError(RunParameterType.Global, property_name) from e
elif expression.startswith("pipeline().dataset"):
elif (
f"pipeline().dataset.{property_name}" in expression
and not state.contains_parameter_with_type_and_name(RunParameterType.Dataset, property_name)
):
raise ParameterNotFoundError(RunParameterType.Dataset, property_name) from e
elif expression.startswith("pipeline().linkedService"):
elif (
f"pipeline().linkedService.{property_name}" in expression
and not state.contains_parameter_with_type_and_name(RunParameterType.LinkedService, property_name)
):
raise ParameterNotFoundError(RunParameterType.LinkedService, property_name) from e
else:
elif not state.contains_parameter_with_type_and_name(RunParameterType.System, property_name):
raise ParameterNotFoundError(RunParameterType.System, property_name) from e
else:
raise Exception(
f"Unknown error for expression: '{expression}' with property: '{property_name}'. Internal error: '{e}'"
) from e

if missing_variable_match:
variable_name = missing_variable_match.group(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ def get_parameter_by_type_and_name(self, parameter_type: RunParameterType, name:

return parameters[0].value

def contains_parameter_with_type_and_name(self, parameter_type: RunParameterType, name: str) -> bool:
"""Checks if the parameter exists in the state."""
return any(p.name == name and p.type == parameter_type for p in self.parameters)

def is_activity_evaluated_in_scope(self, activity_name: str) -> bool:
"""Checks if an activity was evaluated in the current scope.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,3 +836,52 @@ def test_conditional_expression_with_branching(
else:
with pytest.raises(expected):
expression_runtime.evaluate(expression, state)


@pytest.mark.parametrize(
"run_parameter_type, parameter_prefix",
[
(RunParameterType.Pipeline, "pipeline().parameters"),
(RunParameterType.Global, "pipeline().globalParameters"),
(RunParameterType.Dataset, "pipeline().dataset"),
(RunParameterType.LinkedService, "pipeline().linkedService"),
(RunParameterType.System, "pipeline()"),
],
)
def test_complex_expression_with_missing_parameter(run_parameter_type: RunParameterType, parameter_prefix: str) -> None:
# Arrange
expression = f"@concat(pipeline().parameters.parameter, {parameter_prefix}.parameter2)"
expression_runtime = ExpressionRuntime()
state = PipelineRunState(parameters=[RunParameter(RunParameterType.Pipeline, "parameter", "value")])

# Act
with pytest.raises(ParameterNotFoundError) as exinfo:
expression_runtime.evaluate(expression, state)

# Assert
assert str(exinfo.value) == f"Parameter: 'parameter2' of type '{run_parameter_type}' not found"


@pytest.mark.parametrize(
"run_parameter_type, parameter_prefix",
[
(RunParameterType.Global, "pipeline().globalParameters"),
(RunParameterType.Dataset, "pipeline().dataset"),
(RunParameterType.LinkedService, "pipeline().linkedService"),
(RunParameterType.System, "pipeline()"),
],
)
def test_complex_expression_with_missing_parameter_with_same_name_of_another_type(
run_parameter_type: RunParameterType, parameter_prefix: str
) -> None:
# Arrange
expression = f"@concat(pipeline().parameters.parameter, {parameter_prefix}.parameter)"
expression_runtime = ExpressionRuntime()
state = PipelineRunState(parameters=[RunParameter(RunParameterType.Pipeline, "parameter", "value")])

# Act
with pytest.raises(ParameterNotFoundError) as exinfo:
expression_runtime.evaluate(expression, state)

# Assert
assert str(exinfo.value) == f"Parameter: 'parameter' of type '{run_parameter_type}' not found"

0 comments on commit cce6773

Please sign in to comment.