-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
The has been introduced a change in commit 6aab658 (version 1.2.1) which makes it impossible to test for an not existing attribute on a BaseConfig object instance and use a default using
getattr(base, key, default)
hasattr(base, key)
If the attribute key
doesn't exist, there is always thrown a KeyError
due to the override of the __getattr__
function on BaseConfig
. This is highly impractical and a bigger breaking change in this minor version step.
To Reproduce
Steps to reproduce the behavior:
YAML example:
jobs:
a:
foo: "bar"
is_optional: true
b:
foo: "bar"
Results:
File "/home/user/work/scripts/job.py", line ??, in __init__
conf.is_optional if hasattr(conf, 'is_optional') else None
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/work/lib/python3.11/site-packages/pyaml_env/base_config.py", line 28, in __getattr__
return self.__dict__[field_name]
~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'is_optional'
Expected behavior
getattr and hasattr should work on BaseConfig without limitations.
Additional context
- Python version 3.11
- OS Debian 12
mkaranasou and xolian
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working