Geert
07/04/2023, 11:50 AMFOO = "some_default_value"
@task(environment={"FOO": FOO})
def some_task():
return "bar"
def populate_vars_from_config(config):
print(config.keys())
FOO = config['foo']
@workflow
def some_workflow(config: dict):
populate_vars_from_config()
some_task()
And run it with
pyflyte run ./some_path some_workflow --config ./config.json
However that gives me an exception because its a Promise:
Failed with Unknown Exception <class 'AttributeError'> Reason: Error encountered while executing 'some_workflow':
'Promise' object has no attribute 'keys'
Any suggestions how to approach this in a better way? 🙂
I guess I could just set them myself within the task, but would be nice to have them visible in the decorator.jeev
Geert
07/04/2023, 2:30 PM@workflow
def some_workflow(config: dict):
validated_config = validate_config(config=config)
some_task = task(
some_specific_param=validated_config["some_specific_param"],
)
Which makes it harder to do testing, since you’re creating dependencies on an entire config object in the task function, rather than only what is specifically used (the some_specific_param
parameter).jeev
mykyta luzan
07/04/2023, 8:57 PM@dataclass_json
@dataclass
class Config:
...
@workflow
def some_workflow(config: Config):
...
This should work fine, no?Geert
07/05/2023, 9:47 AMAttributeError
if you try to access a field of the Config class inside the some_workflow
function, because it’s a Promise. Using a dynamic
works for me.Yee