Skip to content

Commit

Permalink
Validate interface variable names
Browse files Browse the repository at this point in the history
Signed-off-by: ddl-rliu <richard.liu@dominodatalab.com>
  • Loading branch information
ddl-rliu committed Jun 27, 2024
1 parent bd4c708 commit cc4d830
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions flytekit/core/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import collections
import copy
import inspect
import re
import typing
from collections import OrderedDict
from typing import Any, Dict, Generator, List, Optional, Tuple, Type, TypeVar, Union, cast
Expand All @@ -21,6 +22,7 @@
from flytekit.models.literals import Literal, Scalar, Void

T = typing.TypeVar("T")
_PYTHON_VARIABLE_NAME_REGEX = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$')


def repr_kv(k: str, v: Union[Type, Tuple[Type, Any]]) -> str:
Expand Down Expand Up @@ -261,6 +263,12 @@ def transform_interface_to_typed_interface(
interface.docstring.output_descriptions, interface.outputs
)

# Assert valid interface variable names
for key in interface.inputs.keys():
assert _PYTHON_VARIABLE_NAME_REGEX.match(key), f"Invalid input name: '{key}'. Inputs must be valid Python variable names."
for key in interface.outputs.keys():
assert _PYTHON_VARIABLE_NAME_REGEX.match(key), f"Invalid output name: '{key}'. Outputs must be valid Python variable names."

inputs_map = transform_variable_map(interface.inputs, input_descriptions)
outputs_map = transform_variable_map(interface.outputs, output_descriptions)
verify_outputs_artifact_bindings(interface.inputs, outputs_map, allow_partial_artifact_id_binding)
Expand Down

0 comments on commit cc4d830

Please sign in to comment.