1- from typing import Any , Dict , Optional , Union
1+ from typing import Any , Dict , Literal , Optional , Union
22
33import pydantic
44from taskiq import AsyncBroker , AsyncTaskiqDecoratedTask , TaskiqResult
55from taskiq .kicker import AsyncKicker
66
77from taskiq_pipelines .abc import AbstractStep
8- from taskiq_pipelines .constants import CURRENT_STEP , PIPELINE_DATA
8+ from taskiq_pipelines .constants import CURRENT_STEP , EMPTY_PARAM_NAME , PIPELINE_DATA
99
1010
1111class SequentialStep (pydantic .BaseModel , AbstractStep , step_name = "sequential" ):
@@ -19,9 +19,17 @@ class SequentialStep(pydantic.BaseModel, AbstractStep, step_name="sequential"):
1919
2020 task_name : str
2121 labels : Dict [str , str ]
22- param_name : Optional [str ]
22+ # order is important here, otherwise pydantic will always choose str.
23+ # we use int instead of Literal[-1] because pydantic thinks that -1 is always str.
24+ param_name : Union [Optional [int ], str ]
2325 additional_kwargs : Dict [str , Any ]
2426
27+ @pydantic .validator ("param_name" )
28+ def validate_param_name (cls , value : Union [Optional [str ], int ]) -> Union [Optional [str ], int ]:
29+ if isinstance (value , int ) and value != EMPTY_PARAM_NAME :
30+ raise ValueError ("must be str, None or -1 (EMPTY_PARAM_NAME)" )
31+ return value
32+
2533 def dumps (self ) -> str :
2634 """
2735 Dumps step as string.
@@ -78,9 +86,11 @@ async def act(
7886 ** {PIPELINE_DATA : pipe_data , CURRENT_STEP : step_number }, # type: ignore
7987 )
8088 )
81- if self .param_name :
89+ if isinstance ( self .param_name , str ) :
8290 self .additional_kwargs [self .param_name ] = result .return_value
8391 await kicker .kiq (** self .additional_kwargs )
92+ elif self .param_name == EMPTY_PARAM_NAME :
93+ await kicker .kiq (** self .additional_kwargs )
8494 else :
8595 await kicker .kiq (result .return_value , ** self .additional_kwargs )
8696
@@ -91,7 +101,7 @@ def from_task(
91101 AsyncKicker [Any , Any ],
92102 AsyncTaskiqDecoratedTask [Any , Any ],
93103 ],
94- param_name : Optional [str ],
104+ param_name : Union [ Optional [str ], int ],
95105 ** additional_kwargs : Any ,
96106 ) -> "SequentialStep" :
97107 """
0 commit comments