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

allows to bubble up exceptions when standalone resource returns #1374

Merged
merged 1 commit into from
May 17, 2024
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
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
Loading