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

Preserving Exception in the LazyEntity fetch #1412

Merged
merged 4 commits into from
Jan 20, 2023
Merged
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
3 changes: 2 additions & 1 deletion flytekit/core/promise.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,8 @@ def create_and_link_node_from_remote(
extra_inputs = used_inputs ^ set(kwargs.keys())
if len(extra_inputs) > 0:
raise _user_exceptions.FlyteAssertion(
"Too many inputs were specified for the interface. Extra inputs were: {}".format(extra_inputs)
f"Too many inputs for [{entity.name}] Expected inputs: {typed_interface.inputs.keys()} "
f"- extra inputs: {extra_inputs}"
)

# Detect upstream nodes
Expand Down
7 changes: 6 additions & 1 deletion flytekit/remote/lazy_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ def entity(self) -> T:
"""
with self._mutex:
if self._entity is None:
self._entity = self._getter()
try:
self._entity = self._getter()
except AttributeError as e:
raise RuntimeError(
f"Error downloading the entity {self._name}, (check original exception...)"
) from e
return self._entity

def __getattr__(self, item: str) -> typing.Any:
Expand Down
13 changes: 13 additions & 0 deletions tests/flytekit/unit/remote/test_lazy_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,16 @@ def _getter():
e.compile(ctx)
assert e._entity is not None
assert e.entity == dummy_task


def test_lazy_loading_exception():
def _getter():
raise AttributeError("Error")

e = LazyEntity("x", _getter)
assert e.name == "x"
assert e._entity is None
with pytest.raises(RuntimeError) as exc:
assert e.blah

assert isinstance(exc.value.__cause__, AttributeError)