Skip to content

[WIP] [BUG] At least one of default_image or images must be provided in ImageConfig #3163

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions flytekit/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@ class ImageConfig(DataClassJsonMixin):
default_image: Optional[Image] = None
images: Optional[List[Image]] = None

def __post_init__(self) -> None:
"""Ensure that at least one of 'default_image' or 'images' is provided.

If both are missing, an error is raised to prevent invalid configuration.
For more details, see https://github.com/flyteorg/flyte/issues/6157.
"""
if self.default_image is None and self.images is None:
raise ValueError("Either 'default_image' or 'images' must be provided.")

def find_image(self, name) -> Optional[Image]:
"""
Return an image, by name, if it exists.
Expand Down
2 changes: 2 additions & 0 deletions flytekit/core/python_auto_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ def get_registerable_container_image(img: Optional[Union[str, ImageSpec]], cfg:
else:
raise AssertionError(f"Only fqn and version are supported replacements, {attr} is not supported")
return img
# At least one of 'default_image' or 'images' must be provided
# Could we remove the following check?
if cfg.default_image is None:
raise ValueError("An image is required for PythonAutoContainer tasks")
return cfg.default_image.full
Expand Down
8 changes: 6 additions & 2 deletions flytekit/extend/backend/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ def execute(self: PythonTask, **kwargs) -> LiteralMap:
from flytekit.tools.translator import get_serializable

ctx = FlyteContext.current_context()
ss = ctx.serialization_settings or SerializationSettings(ImageConfig())
# If ctx.serialization_settings is None, a default image must be provided.
# For more details, see https://github.com/flyteorg/flyte/issues/6157.
ss = ctx.serialization_settings or SerializationSettings(ImageConfig.auto_default_image())
task_template = get_serializable(OrderedDict(), ss, self).template
output_prefix = ctx.file_access.get_random_remote_directory()

Expand Down Expand Up @@ -329,7 +331,9 @@ class AsyncAgentExecutorMixin:

def execute(self: PythonTask, **kwargs) -> LiteralMap:
ctx = FlyteContext.current_context()
ss = ctx.serialization_settings or SerializationSettings(ImageConfig())
# If ctx.serialization_settings is None, a default image must be provided.
# For more details, see https://github.com/flyteorg/flyte/issues/6157.
ss = ctx.serialization_settings or SerializationSettings(ImageConfig.auto_default_image())
output_prefix = ctx.file_access.get_random_remote_directory()
self.resource_meta = None

Expand Down
9 changes: 4 additions & 5 deletions tests/flytekit/unit/core/test_python_function_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,10 @@ def test_container_image_conversion(mock_image_spec_builder):
assert get_registerable_container_image(image_spec, cfg) == image_spec.image_name()


def test_get_registerable_container_image_no_images():
cfg = ImageConfig()

with pytest.raises(ValueError):
get_registerable_container_image("", cfg)
def test_empty_image_config():
ERR_MSG = "Either 'default_image' or 'images' must be provided."
with pytest.raises(ValueError, match=ERR_MSG):
cfg = ImageConfig()


def test_py_func_task_get_container():
Expand Down
Loading