#7055 [v2][Run Service] write empty input Literal if no input
Pull request opened by
machichima
Tracking issue
Why are the changes needed?
When running task without input, we will get following errors in pod
FileNotFoundError: Object at location testorg/testproject/development/r9dl4lm95nvzfsftp84f/inputs/inputs.pb not found: Error performing HEAD
http://flyte-sandbox-minio.flyte:9000/flyte-data/testorg/testproject/development/r9dl4lm95nvzfsftp84f/inputs/inputs.pb in 2.922346ms - Server returned non-2xx status code: 404 Not Found:
This is because runtime always expect input file exists, but originally we do not write input file if there's no input for the action.
What changes were proposed in this pull request?
This PR writes an empty input if there's no input provided in the action
How was this patch tested?
Run with following script and ensure there's no error
# modified from the examples/basics/hello.py in flyte-sdk
import flyte
# TaskEnvironments provide a simple way of grouping configuration used by tasks (more later).
env = flyte.TaskEnvironment(
name="hello_world",
resources=flyte.Resources(memory="250Mi"),
)
# use TaskEnvironments to define tasks, which are regular Python functions.
@env.task
def fn(x: int) -> int: # type annotations are recommended.
slope, intercept = 2, 5
return slope * x + intercept
# tasks can also call other tasks, which will be manifested in different containers.
@env.task
def main() -> float:
x_list: list[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
x_len = len(x_list)
if x_len < 10:
raise ValueError(f"x_list doesn't have a larger enough sample size, found: {x_len}")
y_list = list(flyte.map(fn, x_list)) # flyte.map is like Python map, but runs in parallel.
y_mean = sum(y_list) / len(y_list)
return y_mean
if
name == "__main__":
flyte.init_from_config() # establish remote connection from within your script.
run = flyte.run(main) # run remotely inline and pass data.
# print various attributes of the run.
print(run.name)
print(run.url)
run.wait() # stream the logs from the root action to the terminal.
Result:
❯ python examples/basics/hello.py
> Building 1 image...
> Building image flyte for environment hello_world
i Image
ghcr.io/flyteorg/flyte:16b2b307f1864d4a76e0224b38da6444 already exists, skipping build
✓ Built image for environment hello_world:
ghcr.io/flyteorg/flyte:16b2b307f1864d4a76e0224b38da6444
> Bundling code...
✓ Code bundle: 1 files, 0.009765625 MB (compressed 0.0008516311645507812 MB)
> Uploading code bundle...
rhl2rxlhk68x5b5ntmh7
http://localhost:8080/v2/domain/development/project/testproject/runs/rhl2rxlhk68x5b5ntmh7
Run 'rhl2rxlhk68x5b5ntmh7' completed successfully.
Labels
Please add one or more of the following labels to categorize your PR:
•
added: For new features.
•
changed: For changes in existing functionality.
•
deprecated: For soon-to-be-removed features.
•
removed: For features being removed.
•
fixed: For any bug fixed.
•
security: In case of vulnerabilities
This is important to improve the readability of release notes.
Setup process
Screenshots
Check all the applicable boxes
• I updated the documentation accordingly.
• All new and existing tests passed.
• All commits are signed-off.
Related PRs
Docs link
flyteorg/flyte