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

Unexpected Behavior when Parsing Duplicate Key #197

Closed
wg99 opened this issue Jul 30, 2019 · 3 comments · Fixed by #260
Closed

Unexpected Behavior when Parsing Duplicate Key #197

wg99 opened this issue Jul 30, 2019 · 3 comments · Fixed by #260

Comments

@wg99
Copy link

wg99 commented Jul 30, 2019

Hello. I started using this package yesterday and I am sorry if I am missing something simple.
I am trying to read an env file that looks like this:

export hello=hi
export greetings=${hello}
export goodbye=bye
export greetings=${goodbye}

To read it, I wrote the following small program:

import os
import dotenv
from pathlib import Path

env_path = './test.env'
dotenv.load_dotenv(dotenv_path=env_path,verbose=True)
print(os.getenv('greetings'))

When I run this program, it outputs a single empty line. This happens even when I set override to True. I was expecting the program to output 'bye'. Is this a bug or the expected behavior for handling duplicate keys ? I am currently running 3.7.3 and python-dotenv version 0.10.3. Thank you.

@wg99
Copy link
Author

wg99 commented Jul 30, 2019

Quick update. I just tried the program again with the following env file:

export hello=hi
export goodbye=bye
export greetings=${hello}
export greetings=${goodbye}

This time, my program output 'bye'.

I am not sure why changing the order allowed greetings to be resolved correctly but I thought that I should include this information.

@bbc2
Copy link
Collaborator

bbc2 commented Jul 30, 2019

I can reproduce this issue. Your program should indeed print "bye".

@bbc2
Copy link
Collaborator

bbc2 commented Jul 3, 2020

I've created an MR (#260) with a fix for the issue your reported. If you want you can try it and let me know if it works for you. Otherwise I'll just go ahead and merge it.

@bbc2 bbc2 closed this as completed in #260 Jul 16, 2020
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

Successfully merging a pull request may close this issue.

2 participants