Skip to content

Commit

Permalink
Preserving Exception in the LazyEntity fetch (flyteorg#1412)
Browse files Browse the repository at this point in the history
* Preserving Exception in the LazyEntity fetch

Signed-off-by: Ketan Umare <[email protected]>

* updated lint error

Signed-off-by: Ketan Umare <[email protected]>

* more tests

Signed-off-by: Ketan Umare <[email protected]>

Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: byhsu <[email protected]>
  • Loading branch information
kumare3 authored and ByronHsu committed Feb 1, 2023
1 parent d3d258d commit 0cf7a35
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
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)

0 comments on commit 0cf7a35

Please sign in to comment.