KEMBAR78
Override / interpolate of variables working incorrectly · Issue #256 · theskumar/python-dotenv · GitHub
Skip to content

Override / interpolate of variables working incorrectly #256

@hectorvs

Description

@hectorvs

Bug is a combination of override and interpolate.

contents of files is as follows:

foo.txt

Name=foo
Interpolate="${Name}/baz"

bar.txt

Name=bar
Interpolate="${Name}/baz"

test file:

from dotenv import load_dotenv
import os

def print_env():
    for key in os.environ.keys():
       print("{}: {}".format(key, os.getenv(key)))

load_dotenv('foo.txt', override=True)
print_env()

load_dotenv('bar.txt', override=True)
print_env()

when second print_env() runs, the values are:

Name=bar
Interpolate=foo/baz # should be bar/baz

the reason for this is that the resolve_nested_variables method looks into existing ENV vars first and then looks at the current file's loaded values. (in our case, Name was loaded in the earlier file with value foo).

I believe the correct functionality would be to first look into the loaded file's values and then on the environment in order to keep the same behavior as the first file loaded.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions