Skip to content

fix: evaluate indexed values in local conditionals - #3468

Open
1fanwang wants to merge 1 commit into
flyteorg:masterfrom
1fanwang:1fannnw/fix-indexed-none-conditional
Open

1fanwang wants to merge 1 commit into
flyteorg:masterfrom
1fanwang:1fannnw/fix-indexed-none-conditional

Conversation

@1fanwang

Copy link
Copy Markdown
Contributor

Tracking issue

Related to flyteorg/flyte#6473.

Why are the changes needed?

A local workflow cannot check whether an indexed list entry is None. It raises AttributeError: 'NoneType' object has no attribute 'union' instead of selecting a branch.

What changes were proposed in this pull request?

Resolve indexed operands before evaluating a comparison, using the existing attribute-path resolver. Resolution works on a copy so other uses of the promise keep its original value. Compilation still retains the indexed reference.

How was this patch tested?

The reproducer below fails on current master and succeeds with this change through the same pyflyte run command. This exercises local Flytekit execution without mocks; it does not use a remote Flyte cluster.

Testing Done

Source Result
Current master AttributeError: 'NoneType' object has no attribute 'union', exit 1
This change Task succeeded, exit 0

The base was d69b3fb.

Setup process

Reproducer and raw output

I used Python 3.12.9 and the repository's development requirements in a virtual environment:

SETUPTOOLS_SCM_PRETEND_VERSION=1.999.0dev0 UV_CONCURRENT_BUILDS=1 UV_CONCURRENT_INSTALLS=2 uv pip install --python .venv/bin/python -r dev-requirements.in

Save this as repro_6473_public.py in the checkout and put that virtual environment's executables on PATH:

from typing import Optional, Union

from flytekit import conditional, task, workflow
from flytekit.core.task import Echo

echo: Echo = Echo(name="branch_result", inputs={"value": str})


@task
def check_status() -> list[Optional[bool]]:
    return [None, True]


@workflow
def wf() -> Optional[Union[str, bool]]:
    status = check_status()[0]
    return (
        conditional("status_check")
        .if_(status.is_none())
        .then(echo(value="Task succeeded"))
        .else_()
        .then(echo(value="Task failed"))
    )

I ran these commands in the base and patched checkouts:

export PYTHONPATH=.
pyflyte run repro_6473_public.py wf > result.log 2>&1
status=$?
grep -E '^(Running Execution|AttributeError|Task succeeded)' result.log
printf 'exit_code=%s\n' "$status"

Base:

Running Execution on local.
AttributeError: 'NoneType' object has no attribute 'union'
exit_code=1

Patched:

Running Execution on local.
Task succeeded
exit_code=0

Regression cases cover optional boolean entries, right-hand indexed comparisons and serialized reference paths. The existing conditional integration workflow also ran locally with all four combinations of its boolean inputs.

Screenshots

Not applicable.

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

The documented API is unchanged, so this does not need a documentation update.

Related PRs

None.

Docs link

Not applicable.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant