1
1
from __future__ import annotations
2
2
3
- from typing import List , Literal , Optional , Type
3
+ from typing import List , Literal , Optional , Type , Any
4
4
5
5
from socon .core .registry import projects
6
6
14
14
class Task (Base , Nameable ):
15
15
"""Call a module (action) with specific arguments and other parameters"""
16
16
17
- action : Type
17
+ action : Any
18
18
args : dict = {}
19
19
20
20
retries : Optional [int ] = 0
@@ -31,6 +31,12 @@ def preprocess_action(cls, values):
31
31
if "args" in values :
32
32
args = values ["args" ]
33
33
34
+ # If the application registry filters some of the apps,
35
+ # the validation will need to be retriggered and the action
36
+ # will already be an instance. To avoid that, we check if we already have an action instance and return it as his.
37
+ if isinstance (action , object ) and action is not None :
38
+ return values
39
+
34
40
# filter out task attributes so we're only querying unrecognized keys as actions/modules
35
41
non_task_values = dict (
36
42
(k , v ) for k , v in values .items () if (k not in get_field_names (Task ))
@@ -44,7 +50,6 @@ def preprocess_action(cls, values):
44
50
is_action_candidate = True
45
51
46
52
if is_action_candidate :
47
-
48
53
# finding more than one module name is a problem
49
54
if action is not None :
50
55
raise ParserError (
@@ -82,7 +87,8 @@ def preprocess_action(cls, values):
82
87
@model_validator (mode = "after" )
83
88
def post_process_action (self ):
84
89
"""Validate the action schema"""
85
- self .action = self .action (self )
90
+ if isinstance (self .action , type ):
91
+ self .action = self .action (self )
86
92
return self
87
93
88
94
0 commit comments