fix: treat a .pyiceberg.yaml without a mapping as no config - #3915
Merged
Conversation
`_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>
Contributor
There was a problem hiding this comment.
🟢 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_yamlso non-mapping YAML documents returnNoneinstead of being passed into_lowercase_dictionary_keys. - Add a parametrized regression test covering empty, newline-only, and comment-only
.pyiceberg.yamlcontents.
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
approved these changes
Sep 7, 2026
Fokko
left a comment
Contributor
There was a problem hiding this comment.
Sounds like a very reasonable change, thanks @jackylee-ch for fixing this 👍
Contributor
Author
|
Thanks. @Fokko |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
_load_yamlpassesstrictyaml.load(...).datastraight to_lowercase_dictionary_keys. For an empty or comment-only document that value is astr, not a mapping, so the call raisesAttributeError: 'str' object has no attribute 'items'.Config()runs at import time, so commenting out~/.pyiceberg.yamlmakes the import fail with an error that names neither YAML nor the file:Return
Noneinstead. The annotated return type is alreadyRecursiveDict | None, and the caller already treatsNoneas "keep looking in the next directory".Are these changes tested?
Yes,
test_from_configuration_files_without_a_mappingintests/utils/test_config.py, parametrized over an empty file, a newline, and a comment-only file. All three fail with theAttributeErrorwithout the change.Are there any user-facing changes?
A
.pyiceberg.yamlthat holds no mapping is skipped instead of raising.