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.

3.18 - It looks like this has broken integration with environment variables.

See original GitHub issue

@rochacbruno @jyejare It looks like this has broken integration with environment variables.

If I have dynaconf 3.1.8 installed, and the combination of:

  1. settings.yaml field key (nested one level from top map) is present, value is empty
  2. validator with default=None for given field key
  3. envvar set for nested field key (DYNACONF_something__field_key)
  4. settings object configuration that looks like: https://github.com/SatelliteQE/robottelo/blob/master/robottelo/config/__init__.py#L18

My envvar value is no longer set in the resulting box instance, it takes the validator default of None.

I confirmed its this line in particular by modifying the file in site-packages with 3.1.8 installed.

_Originally posted by @mshriver in https://github.com/rochacbruno/dynaconf/pull/729#discussion_r853220515_

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
jmwielandtcommented, May 11, 2022

Hi, I’ve written some tests using pytest for this issue which could be added to https://github.com/rochacbruno/dynaconf/blob/master/tests/test_validators.py.

import os
from dynaconf import Dynaconf, Validator


def test_default_eq_env_lvl_1():
    """Tests when the env value equals the default value."""
    VAR_NAME = "test"
    ENV = "TEST"
    settings = Dynaconf(
        environments=False,
        envvar_prefix=False,
        validators=[
            Validator(
                VAR_NAME,
                default=True,
                is_type_of=bool,
            ),
        ],
    )
    os.environ[ENV] = "true"
    assert settings.test is True
    del os.environ[ENV]


def test_default_lvl_1():
    """Tests if the default works propperly without any nested level.

    Uses different values for the default and the environment variable.
    """
    VAR_NAME = "test"
    ENV = "TEST"
    settings = Dynaconf(
        environments=False,
        envvar_prefix=False,
        validators=[
            Validator(
                VAR_NAME,
                default=True,
                is_type_of=bool,
            ),
        ],
    )
    os.environ[ENV] = "false"
    assert settings.test is False
    del os.environ[ENV]


def test_default_lvl_2():
    """Tests if the default works propperly with one nested level.

    Uses different values for the default and the environment variable.
    """
    VAR_NAME = "nested.test"
    ENV = "NESTED__TEST"
    settings = Dynaconf(
        environments=False,
        envvar_prefix=False,
        validators=[
            Validator(
                VAR_NAME,
                default=True,
                is_type_of=bool,
            ),
        ],
    )
    os.environ[ENV] = "false"
    assert settings.nested.test is False
    del os.environ[ENV]

Again: dynaconf 3.1.7 works fine, but dynaconf 3.1.8 don’t.

2reactions
rochacbrunocommented, Apr 19, 2022

@mshriver tracking on this issue, so we can try to fix for both use cases and release 3.1.9 ASAP

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment Placeholders in GitHub Integration Cause Build ...
We're attempting to do an initial configuration of our Backstage deployment using the Docker method and including environment placeholders in the ...
Read more >
Python Integration (Pipe is broken) - UiPath Community Forum
I have problem with python integration when I import some libraries as shown in the 1st picture it shows me the message: “pipe...
Read more >
Environment Variables - The Cargo Book
Environment Variables. Cargo sets and reads a number of environment variables which your code can detect or override. Here is a list of...
Read more >
Environment Variables: What They Are and How To Use Them
A separate line of dynamic environment variables is available in Windows and DOS-based systems, known as pseudo environment variables.
Read more >
Maintaining Your PETSc Installation(s)
$PETSC_ARCH is only needed for in-place installations. ... These variables can be set as environment variables or specified on the command line:.
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