Skip to content

fix: ImageSpec.is_container returns False when no execution is in progress - #3490

Open
mitsa-ng wants to merge 1 commit into
flyteorg:masterfrom
mitsa-ng:fix-imagespec-is-container-registration
Open

mitsa-ng wants to merge 1 commit into
flyteorg:masterfrom
mitsa-ng:fix-imagespec-is-container-registration

Conversation

@mitsa-ng

Copy link
Copy Markdown

Tracking issue

Fixes flyteorg/flyte#6518

Why are the changes needed?

ImageSpec.is_container() fell through to True when the execution state or its mode was None. That is exactly the state during the module import performed by pyflyte register and pyflyte run --remote, so module-level code gated on is_container ran on the registration machine instead of in the built image:

image_spec = ImageSpec(packages=["pandas"], registry=...)

if image_spec.is_container():  # True during fast registration
    import pandas             # executed on the registration machine

What changes were proposed in this pull request?

  • When no execution is in progress (execution_state is None or execution_state.mode is None), is_container now returns False.
  • Local workflow execution (LOCAL_WORKFLOW_EXECUTION) still returns True, and every other mode still compares the _F_IMG_ID environment variable against the spec id, so behavior inside a container built from the spec is unchanged.

How was this patch tested?

  • Updated the assertion in test_image_spec that covered the no-execution case (it asserted the old fall-through True).
  • Added test_is_container_without_execution_in_progress, test_is_container_in_local_workflow_execution, and test_is_container_in_task_execution_compares_image_id covering all three states. The new no-execution test fails on master and passes with this change.
  • pytest tests/flytekit/unit/core/image_spec: 60 passed, 2 skipped.
  • Full tests/flytekit/unit/core run with and without this change produces an identical pre-existing failure set in the local environment (33 environment-related failures on master as well), i.e. no new failures.

Setup process

pytest tests/flytekit/unit/core/image_spec/test_image_spec.py -q

…gress

is_container fell through to True when the execution state or its mode
was None, which is the state during the module import performed by
pyflyte register and pyflyte run --remote. Module-level code gated on
is_container, such as

if image_spec.is_container():
    import pandas

therefore ran at registration time on the registration machine instead
of in the built image.

Return False when no execution is in progress, keep True for local
workflow execution, and keep the env comparison for the rest.

Fixes flyteorg/flyte#6518
@welcome

welcome Bot commented Nov 23, 2026

Copy link
Copy Markdown

Thank you for opening this pull request! 🙌

These tips will help get your PR across the finish line:

  • Most of the repos have a PR template; if not, fill it out to the best of your knowledge.
  • Sign off your commits (Reference: DCO Guide).

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.

[BUG] ImageSpec.is_container returns True during fast registration

1 participant