Skip to content

Commit

Permalink
allows to bubble up exceptions when standalone resource returns
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolfix committed May 16, 2024
1 parent 80e7820 commit 072a89e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
15 changes: 6 additions & 9 deletions dlt/extract/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,16 +567,13 @@ def _wrap(*args: Any, **kwargs: Any) -> TDltResourceImpl:
compat_wrapper(actual_resource_name, conf_f, sig, *args, **kwargs),
incremental,
)
except InvalidResourceDataTypeFunctionNotAGenerator as gen_ex:
except InvalidResourceDataTypeFunctionNotAGenerator:
# we allow an edge case: resource can return another resource
try:
# actually call the function to see if it contains DltResource
data_ = conf_f(*args, **kwargs)
if not isinstance(data_, DltResource):
raise
r = data_ # type: ignore[assignment]
except Exception:
raise gen_ex from None
# actually call the function to see if it contains DltResource
data_ = conf_f(*args, **kwargs)
if not isinstance(data_, DltResource):
raise
r = data_ # type: ignore[assignment]
# consider transformer arguments bound
r._args_bound = True
# keep explicit args passed
Expand Down
11 changes: 11 additions & 0 deletions tests/extract/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,17 @@ def rv_resource(name: str):
assert list(r) == [1, 2, 3]


def test_standalone_resource_returning_resource_exception() -> None:
@dlt.resource(standalone=True)
def rv_resource(uniq_name: str = dlt.config.value):
return dlt.resource([1, 2, 3], name=uniq_name, primary_key="value")

# pass through of the exception in `rv_resource` when it returns, not yields
with pytest.raises(ConfigFieldMissingException) as conf_ex:
rv_resource()
assert conf_ex.value.fields == ["uniq_name"]


def test_resource_rename_credentials_separation():
os.environ["SOURCES__TEST_DECORATORS__STANDALONE_SIGNATURE__SECRET_END"] = "5"
assert list(standalone_signature(1)) == [1, 2, 3, 4]
Expand Down

0 comments on commit 072a89e

Please sign in to comment.