Skip to content
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
11 changes: 8 additions & 3 deletions dlt/extract/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,9 @@ def __iter__(self) -> Generator[TDataItem, None, None]:
Container().injectable_context(source_context),
Container().injectable_context(schema_context),
):
pipe_iterator: ManagedPipeIterator = ManagedPipeIterator.from_pipes(self._resources.selected_pipes) # type: ignore
pipe_iterator: ManagedPipeIterator = ManagedPipeIterator.from_pipes(
self._resources.selected_pipes
) # type: ignore
pipe_iterator.set_context([section_context, state_context, schema_context, source_context])
_iter = map(lambda item: item.item, pipe_iterator)
return flatten_list_or_items(_iter)
Expand All @@ -629,10 +631,13 @@ def __getattr__(self, resource_name: str) -> DltResource:
# do not intercept dunder attributes (needed for copy/pickle/deepcopy)
if resource_name.startswith("__") and resource_name.endswith("__"):
raise AttributeError(resource_name)
resources = self.__dict__.get("_resources")
if resources is None:
raise AttributeError(resource_name)
try:
return self._resources[resource_name]
return resources[resource_name]
except KeyError:
all_resources = ", ".join(self._resources.keys())
all_resources = ", ".join(resources.keys())
raise AttributeError(
f"Resource `{resource_name}` not found in source `{self.name}`. Available"
f" resources: {all_resources}"
Expand Down
10 changes: 10 additions & 0 deletions tests/extract/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,16 @@ def test_source(no_resources):
assert list(s.with_resources()) == []


def test_source_getattr_without_resources_raises_attribute_error() -> None:
source = DltSource.__new__(DltSource)

with pytest.raises(AttributeError, match="anything"):
source.anything

with pytest.raises(AttributeError, match="_resources"):
source._resources


def test_clone_source() -> None:
@dlt.source
def test_source(no_resources):
Expand Down