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

Restrict Python Version Mismatch between Pickled Object and Remote Envrionment #2848

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 22 additions & 2 deletions flytekit/core/python_auto_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,31 @@
def load_task(self, loader_args: List[str]) -> PythonAutoContainerTask:
_, entity_name, *_ = loader_args
import gzip
import sys

import cloudpickle

with gzip.open(PICKLE_FILE_PATH, "r") as f:
entity_dict = cloudpickle.load(f)
try:
with gzip.open(PICKLE_FILE_PATH, "r") as f:
entity_dict = cloudpickle.load(f)
except TypeError:
raise RuntimeError(

Check warning on line 305 in flytekit/core/python_auto_container.py

View check run for this annotation

Codecov / codecov/patch

flytekit/core/python_auto_container.py#L304-L305

Added lines #L304 - L305 were not covered by tests
"The Python version is smaller than the version used to create the pickle file. "
f"Current Python version: {sys.version_info.major}.{sys.version_info.minor}. "
"Please try using the same Python version to create the pickle file or use another "
"container image with a matching version."
)

pickled_version = entity_dict["metadata"]["python_version"].split(".")
if sys.version_info.major != int(pickled_version[0]) or sys.version_info.minor != int(pickled_version[1]):
raise RuntimeError(
"The Python version used to create the pickle file is different from the current Python version. "
f"Current Python version: {sys.version_info.major}.{sys.version_info.minor}. "
f"Python version used to create the pickle file: {entity_dict['metadata']['python_version']}. "
"Please try using the same Python version to create the pickle file or use another "
"container image with a matching version."
)

return entity_dict[entity_name]

def loader_args(self, settings: SerializationSettings, task: PythonAutoContainerTask) -> List[str]: # type:ignore
Expand Down
5 changes: 4 additions & 1 deletion flytekit/remote/executions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
"Please wait until the execution has completed before requesting the outputs."
)
if self.error:
raise user_exceptions.FlyteAssertion("Outputs could not be found because the execution ended in failure.")
raise user_exceptions.FlyteAssertion(

Check warning on line 46 in flytekit/remote/executions.py

View check run for this annotation

Codecov / codecov/patch

flytekit/remote/executions.py#L46

Added line #L46 was not covered by tests
"Outputs could not be found because the execution ended in failure. Error message: "
f"{self.error.message}"
)

return self._outputs

Expand Down
Loading
Loading