Skip to content

fix: guard source resource lookup before init#4119

Open
fengjikui wants to merge 1 commit into
dlt-hub:develfrom
fengjikui:codex/dlt-source-getattr-guard
Open

fix: guard source resource lookup before init#4119
fengjikui wants to merge 1 commit into
dlt-hub:develfrom
fengjikui:codex/dlt-source-getattr-guard

Conversation

@fengjikui

Copy link
Copy Markdown

Fixes #4107.

What changed

  • Make DltSource.__getattr__ read _resources directly from __dict__ before attempting resource-name lookup.
  • Raise AttributeError cleanly when _resources is missing, which can happen for partially initialized / restored objects.
  • Add a regression test for a DltSource.__new__(DltSource) instance accessing both a normal missing attribute and _resources itself.

Why

__getattr__ previously accessed self._resources while handling a missing attribute. If _resources was not present yet, that lookup recursively called __getattr__("_resources") until Python raised RecursionError.

The new guard avoids re-entering the attribute machinery and preserves the existing resource lookup behavior once _resources exists.

Validation

  • Reproduced on current origin/devel before the fix: DltSource.__new__(DltSource).anything raised RecursionError.
  • uv run pytest tests/extract/test_sources.py::test_source_getattr_without_resources_raises_attribute_error tests/extract/test_sources.py::test_select_resources tests/extract/test_sources.py::test_clone_source -q -> 3 passed
  • uv run ruff check dlt/extract/source.py tests/extract/test_sources.py -> All checks passed!
  • uv run ruff format --check dlt/extract/source.py tests/extract/test_sources.py -> 2 files already formatted
  • git diff --check -> clean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DltSource.__getattr__ infinite recursion when _resources missing (e.g. during deepcopy/pickle restore)

1 participant