Skip to content

Commit 3d70018

Browse files
feat(executors): validate workflow file
1 parent fb468b8 commit 3d70018

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

libs/executors/garf/executors/workflow.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@
1919
import pydantic
2020
import smart_open
2121
import yaml
22+
from garf.executors import exceptions
2223
from garf.executors.execution_context import ExecutionContext
2324

2425

26+
class GarfWorkflowError(exceptions.GarfExecutorError):
27+
"""Workflow specific exception."""
28+
29+
2530
class QueryPath(pydantic.BaseModel):
2631
"""Path file with query."""
2732

@@ -57,7 +62,7 @@ class ExecutionStep(ExecutionContext):
5762
"""
5863

5964
fetcher: str | None = None
60-
alias: str | None = None
65+
alias: str | None = pydantic.Field(default=None, pattern=r'^[a-zA-Z0-9_]+$')
6166
queries: list[QueryPath | QueryDefinition] | None = None
6267

6368
@property
@@ -84,7 +89,10 @@ def from_file(cls, path: str | pathlib.Path | os.PathLike[str]) -> Workflow:
8489
"""Builds workflow from local or remote yaml file."""
8590
with smart_open.open(path, 'r', encoding='utf-8') as f:
8691
data = yaml.safe_load(f)
87-
return Workflow(steps=data.get('steps'))
92+
try:
93+
return Workflow(**data)
94+
except pydantic.ValidationError as e:
95+
raise GarfWorkflowError(f'Incorrect workflow:\n {e}') from e
8896

8997
def save(self, path: str | pathlib.Path | os.PathLike[str]) -> str:
9098
"""Saves workflow to local or remote yaml file."""

0 commit comments

Comments
 (0)