Skip to content

fix: treat a .pyiceberg.yaml without a mapping as no config - #3915

Merged
Fokko merged 1 commit into
apache:mainfrom
jackylee-ch:fix-empty-pyiceberg-yaml
Sep 7, 2026
Merged

fix: treat a .pyiceberg.yaml without a mapping as no config#3915
Fokko merged 1 commit into
apache:mainfrom
jackylee-ch:fix-empty-pyiceberg-yaml

Conversation

@jackylee-ch

Copy link
Copy Markdown
Contributor

Rationale for this change

_load_yaml passes strictyaml.load(...).data straight to _lowercase_dictionary_keys. For an empty or comment-only document that value is a str, not a mapping, so the call raises AttributeError: 'str' object has no attribute 'items'.

Config() runs at import time, so commenting out ~/.pyiceberg.yaml makes the import fail with an error that names neither YAML nor the file:

>>> import pyiceberg.catalog
AttributeError: 'str' object has no attribute 'items'

Return None instead. The annotated return type is already RecursiveDict | None, and the caller already treats None as "keep looking in the next directory".

Are these changes tested?

Yes, test_from_configuration_files_without_a_mapping in tests/utils/test_config.py, parametrized over an empty file, a newline, and a comment-only file. All three fail with the AttributeError without the change.

Are there any user-facing changes?

A .pyiceberg.yaml that holds no mapping is skipped instead of raising.

`_load_yaml` passed `strictyaml.load(...).data` straight to
`_lowercase_dictionary_keys`. For an empty or comment-only document that
value is a `str`, not a mapping, so the call raised
`AttributeError: 'str' object has no attribute 'items'`.

`Config()` runs at import time, so commenting out the file made
`import pyiceberg.catalog` fail with an error naming neither YAML nor the
file. Return `None` instead, which the annotated return type already allows
and which the caller already handles as "keep looking".

Co-Authored-By: Claude Code <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 7, 2026 03:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped, matches the stated rationale, and is covered by a focused regression test for the previously failing cases.

Pull request overview

This PR fixes a failure mode in pyiceberg.utils.config.Config where an empty or comment-only .pyiceberg.yaml could cause an AttributeError during import-time configuration loading. It does this by treating configuration files that don’t parse to a mapping as “no config” and continuing the normal lookup behavior.

Changes:

  • Guard _load_yaml so non-mapping YAML documents return None instead of being passed into _lowercase_dictionary_keys.
  • Add a parametrized regression test covering empty, newline-only, and comment-only .pyiceberg.yaml contents.
File summaries
File Description
pyiceberg/utils/config.py Adds a type guard to skip non-mapping YAML documents during config file loading.
tests/utils/test_config.py Adds a regression test ensuring non-mapping config files are treated as absent.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a very reasonable change, thanks @jackylee-ch for fixing this 👍

@Fokko
Fokko added this pull request to the merge queue Sep 7, 2026
Merged via the queue into apache:main with commit 75b74cf Sep 7, 2026
21 checks passed
@jackylee-ch

Copy link
Copy Markdown
Contributor Author

Thanks. @Fokko

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.

3 participants