Skip to content

Commit

Permalink
Fix - Order of variables break parsing (#869) (#933)
Browse files Browse the repository at this point in the history
* fix order of variables break parsing (#869)

* fix linting

---------

Co-authored-by: Bruno Rocha <rochacbruno@users.noreply.github.com>
  • Loading branch information
pedro-psb and rochacbruno committed May 16, 2023
1 parent 920a969 commit 713fc7d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dynaconf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from dynaconf.utils.functional import LazyObject
from dynaconf.utils.parse_conf import converters
from dynaconf.utils.parse_conf import get_converter
from dynaconf.utils.parse_conf import Lazy
from dynaconf.utils.parse_conf import parse_conf_data
from dynaconf.utils.parse_conf import true_values
from dynaconf.validator import ValidationError
Expand Down Expand Up @@ -900,7 +901,11 @@ def set(

value = parse_conf_data(value, tomlfy=tomlfy, box_settings=self)
key = upperfy(key.strip())
existing = getattr(self, key, None)

# Fix for #869 - The call to getattr trigger early evaluation
existing = (
getattr(self, key, None) if not isinstance(value, Lazy) else None
)

if getattr(value, "_dynaconf_del", None):
# just in case someone use a `@del` in a first level var.
Expand Down
4 changes: 4 additions & 0 deletions tests_functional/issues/869_order_break_parsing/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DYNACONF_ROOT="@jinja {{ this.root_rel | abspath }}"
DYNACONF_SUBDIR="@format {this.root}/dotenv"
DYNACONF_ROOT_REL=".."
DYNACONF_MERGING=["@format {this.ROOT_REL}", "dynaconf_merge"]
18 changes: 18 additions & 0 deletions tests_functional/issues/869_order_break_parsing/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations

from pathlib import Path

from dynaconf import Dynaconf

settings = Dynaconf(
settings_file="settings.yaml",
load_dotenv=True,
)

# issue example
assert settings.as_dict()
assert settings.ROOT == str(Path().absolute().parent)

# possible merging side-effects related to workaround
assert settings.MERGING[0] == settings.SUBDIR
assert settings.MERGING[1] == settings.ROOT_REL
3 changes: 3 additions & 0 deletions tests_functional/issues/869_order_break_parsing/settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MERGING: ["@jinja {{ this.SUBDIR }}"]
SUBDIR: "@jinja {{ this.ROOT }}/yaml"
ROOT: "../.."

0 comments on commit 713fc7d

Please sign in to comment.