Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Being able to get a set of all missing keys #720

Closed
Ohad31415 opened this issue May 19, 2021 · 4 comments
Closed

Being able to get a set of all missing keys #720

Ohad31415 opened this issue May 19, 2021 · 4 comments
Milestone

Comments

@Ohad31415
Copy link
Contributor

Ohad31415 commented May 19, 2021

Something I find myself use each time is a function that returns set of all missing keys so that if it's not empty by the end of the configuration setup I raise an error.
This function consists of recursive calls to OmegaConf.is_missing and OmegaConf.is_confg and I think it would be helpful to include it under the library.

The function implementation is something like this -

class OmegaConf:
    # ...
    @staticmethod
    def missing_keys(cfg: Container) -> Set[str]:
        missings = set()

        def gather(_cfg, prefix=""):
            for key in _cfg:
                if OmegaConf.is_missing(_cfg, key):
                    missings.add(f"{prefix}{key}")
                elif OmegaConf.is_config(_cfg[key]):
                    gather(_cfg[key], prefix=f"{prefix}{key}.")

        gather(cfg)
        return missings 

I've set a PR for this here #719

@Ohad31415 Ohad31415 changed the title Being able to a set of all missing keys Being able to get a set of all missing keys May 19, 2021
@omry
Copy link
Owner

omry commented May 19, 2021

Thanks @Ohad31415.
This is something we can consider for OmegaConf 2.2 (which is pretty far away right now).
I am not planning to add any new features to OmegaConf 2.1.

I am going to hold off reviewing the PR until we start working on 2.2.

@Jasha10
Copy link
Collaborator

Jasha10 commented May 19, 2021

This functionality is similar to the proposed throw_on_missing keyword argument for OmegaConf.to_container (#501).

@Ohad31415
Copy link
Contributor Author

This functionality is similar to the proposed throw_on_missing keyword argument for OmegaConf.to_container (#501).

It's similar in the sense that they both report missing keys, however throw_on_missing doesn't give a list of the missing keys so that one get prompt that in an error.

@Jasha10
Copy link
Collaborator

Jasha10 commented May 20, 2021

Yes, that is correct -- the proposed throw_on_missing error message would only report the first missing key that is encountered.

@pixelb pixelb closed this as completed Apr 7, 2022
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

No branches or pull requests

4 participants