question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
omrycommented, Jan 8, 2021

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.

from typing import Any

from omegaconf import ListConfig, DictConfig, OmegaConf, MissingMandatoryValue

def fail_on_missing(cfg: Any) -> None:
    if isinstance(cfg, ListConfig):
        for x in cfg:
            fail_on_missing(x)
    elif isinstance(cfg, DictConfig):
        for _, v in cfg.items():
            fail_on_missing(v)
1reaction
omrycommented, Jul 19, 2020

I need to think this through though, so I may still end up abandoning this idea.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found