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

[RFC] Add option to validate only current env in validators.validate #734

Closed
UgoBena opened this issue Apr 8, 2022 · 2 comments
Closed
Labels
Not a Bug Not a Problem, expected behavior RFC
Milestone

Comments

@UgoBena
Copy link
Contributor

UgoBena commented Apr 8, 2022

Problem
I currently have a problem in a project when trying to validate a configuration. I have some variables in production that I do not have in development environment, and that are contained in a .secrets file not present in my project. I would like to validate the presence of the production variables when I run the project in production environment. However when running the validators, they go through all environments, and thus fail when trying to validate my production environment in development because some variables are missing as the .secrets.yml file is not present.

Proposed Solution
I just wanted to know if you had considered this issue. I did a quick fix on my side by adding a check_only_current_env: bool = False var to all validate functions in validators.py and simply add a check in Validator.validate before the validate_items lines:

if check_only_current_env:
    if settings.current_env in self.envs:
         this._validate_items(...)
    return

I am open to any other solutions and can also make a pull request with this small change.

Thank you very much for the project it's really nice !

@UgoBena UgoBena added Not a Bug Not a Problem, expected behavior RFC labels Apr 8, 2022
@rochacbruno
Copy link
Member

Similar feature has been implemented on #549

this is doable at the validators level, you can pass env to the Validator class init.

You could for example make some validators valid only for production by passing it.

We can think on a more flexible way.

@UgoBena
Copy link
Contributor Author

UgoBena commented Apr 8, 2022

Yes that's exactly what I am doing however these validators will still be run on all environments even if I am in a different environment (development for instance) when I run settings.validators.validate(). Meaning they will fail as I don't have all the required variables in the production settings.

What I suggested was to add the option here to do settings.validators.validate(check_only_current_env=True), kind of like the option to check only or exclude some settings with the only and exclude parameters

UgoBena pushed a commit to UgoBena/dynaconf that referenced this issue Apr 11, 2022
UgoBena pushed a commit to UgoBena/dynaconf that referenced this issue Apr 11, 2022
rochacbruno pushed a commit that referenced this issue Apr 11, 2022
Co-authored-by: Ugo Benassayag <ugo.benassayag@ssi.gouv.fr>
@rochacbruno rochacbruno added this to the 3.1.8 milestone Apr 11, 2022
rochacbruno added a commit that referenced this issue Apr 15, 2022
Shortlog of commits since last release:

    Anderson Sousa (1):
          Document the usage with python -m (#710)

    Andressa Cabistani (2):
          Add unique label when merging lists to fix issue #653 (#661)
          Add new validation to fix issue #585 (#667)

    Armin Berres (1):
          Fix typo in error message

    Bruno Rocha (7):
          Release version 3.1.7
          Found this bug that was duplicating the generated envlist (#663)
          Add support for Python 3.10 (#665)
          Attempt to fix #555 (#669)
          Create update_contributors.yml
          Fixing pre-coomit and docs CI
          Added `dynaconf get` command to cli (#730)

    Caneco (2):
          improvement: add brand new logo to the project (#686)
          improvement: update socialcard to match the python way (#687)

    EdwardCuiPeacock (2):
          Feature: add @Jinja and @Format casting (#704)
          Combo converter doc (#735)

    Eitan Mosenkis (1):
          Fix FlaskConfig.setdefault (#706)

    Enderson Menezes (Mr. Enderson) (2):
          Force PYTHONIOENCODING to utf-8 to fix #664 (#672)
          edit: move discussions to github tab (#682)

    Eugene Triguba (1):
          Fix custom prefix link in envvar documentation (#680)

    Gibran Herrera (1):
          Fix Issue 662 Lazy validation (#675)

    Jitendra Yejare (2):
          Load vault secrets from environment less stores or which are not written by dynaconf (#725)
          Use default value when settings is blank (#729)

    Pavel Alimpiev (1):
          Update docs link (#678)

    Ugo Benassayag (1):
          Added validate_only_current_env to validator (issue #734) (#736)

    Waylon Walker (1):
          Docs Fix Spelling (#696)

    dependabot[bot] (3):
          Bump django from 2.1.5 to 2.2.26 in /example/django_pytest_pure (#711)
          Bump mkdocs from 1.1.2 to 1.2.3 (#715)
          Bump django from 2.2.26 to 2.2.27 in /example/django_pytest_pure (#717)

    github-actions[bot] (2):
          [automated] Update Contributors File (#691)
          [automated] Update Contributors File (#732)

    lowercase00 (1):
          Makes Django/Flask kwargs case insensitive (#721)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not a Bug Not a Problem, expected behavior RFC
Projects
None yet
Development

No branches or pull requests

2 participants