[Feature Request] check `DictConfig` to detect missed mandatory fields
See original GitHub issue🚀 Feature Request
First of all - thanks for a great work!)
I think a lot of people want to use hydra
as a replacement for argparse
. In my particular case, I want to have functionality to check that some mandatory arguments weren’t provided.
Motivation
I want to detect problems as early as possible - and one way is to check that nothing is missed during configuration (at least, mandatory fields - argparse
will throw exception if some arguments weren’t provided)
Pitch
Describe the solution you’d like
Something simple like this in DictConfig
class probably - or in utils
def has_missed_mandatory_args(cfg: DictConfig) -> bool:
"""
Check if some mandatory fields were not provided.
:param cfg: config to check.
:return: True if missed, False if not missed.
"""
assert isinstance(cfg, DictConfig)
for key in cfg:
try:
if isinstance(cfg[key], DictConfig):
if has_missed_mandatory_args(cfg[key]):
# early stop
return True
except MissingMandatoryValue:
return True
return False
Describe alternatives you’ve considered Implement it by myself - but I could miss some corner cases.
Are you willing to open a pull request? (See CONTRIBUTING)
Yes, I can make PR
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (5 by maintainers)
Top Results From Across the Web
logging.config.dictConfig does not work with callable filters
The filtering logic will check to see if the filter object has a filter ... 'myfilter'" because "noErrorLogs() missing 1 required positional ...
Read more >Structured config — OmegaConf 2.1.3.dev0 documentation
Fields assigned the constant MISSING do not have a value and the value must be set prior to accessing the field. Otherwise a...
Read more >Python Logging Guide - Best Practices and Hands-on Examples
As part of the ongoing logging series, this post describes what you need to discover about Python logging best practices.
Read more >logging-utilities - Python Package Health Analysis - Snyk
Looks like logging-utilities is missing a security policy. ... pull request activity or change in issues status has been detected for the GitHub...
Read more >hydra_zen.structured_configs._implementations — hydra-zen ...
This provides similar functionality to `builds`, but enables a user to ... for f in fields(decorated_obj) if not (f.default is MISSING and f.default_factory ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here is a function that can validate that recursively. You can use it. For now I am not planning on adding it to either Hydra or OmegaConf.
I need to think this through though, so I may still end up abandoning this idea.