Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate WorkflowTask.args based on defaults in WorkflowTask.task.args_schema #639

Closed
tcompa opened this issue Apr 21, 2023 · 2 comments · Fixed by #707
Closed

Populate WorkflowTask.args based on defaults in WorkflowTask.task.args_schema #639

tcompa opened this issue Apr 21, 2023 · 2 comments · Fixed by #707
Labels
High Priority Current Priorities & Blocking Issues

Comments

@tcompa
Copy link
Collaborator

tcompa commented Apr 21, 2023

(based on #638)

Ref:

@tcompa
Copy link
Collaborator Author

tcompa commented Apr 21, 2023

This requires us to understand the structure of the pydantic-generated schemas (see examples in fractal-analytics-platform/fractal-web#82), so that we can reliably extract defaults, including those for nested objects.

When a Task is imported into a Workflow, as a WorkflowTask, its args attribute is filled based on the defaults in the schema.

Other than that, the args attribute can always be modified with the usual PATCH endpoint for WorkflowTask, and how it was created in the first place (from a file, in the CLI client, or from a schema, or from the combination of the two) should not matter.

Note: this issue overrides #592

@tcompa
Copy link
Collaborator Author

tcompa commented May 23, 2023

Here is a snippet that does part of what is needed (e.g. it does not recognize a None default):

from pydantic import BaseModel
from pydantic import Field
from devtools import debug
from typing import Optional


class TaskArguments(BaseModel):
    arg1: int = 1 
    arg2: int = Field(default=1)
    arg3: int
    arg4: Optional[int] = None
    arg5: Optional[int] = Field(default=None)


schema = TaskArguments.schema()
debug(schema)

args = {}
for arg_name, arg_dict in schema["properties"].items():
    debug(arg_name, arg_dict)
    try:
        args[arg_name] = arg_dict["default"]
    except KeyError:
        pass

debug(args)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
High Priority Current Priorities & Blocking Issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant