Feature Request: Exception or Warning on Duplicate Configuration Items

Open
#591 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
devops

Research direction

Start by tracing how py-dotenv handles repeated keys while loading a .env file and review the proposed behavior options. Done should be defined by an agreed API and semantics for warning, strict, latter-covers, and any custom merge logic.

Written by the indexing model from the issue text.

Description

Currently, py-dotenv uses a strategy of overwriting with the latter value when handling configuration items with the same key, that is, using the last value of the repeated key. However, I just wasted an entire morning because there were three configuration items with the same key in my .env file. 😢

To avoid others encountering similar issues, I propose adding an optional behavior parameter. The default should be warning, meaning the latter value overwrites the former but with a warning. It could also be set to strict, which throws an exception, or to latter-covers, which means the latter value overwrites the former without any warning.

I have researched how other libraries handle this issue, for reference:

Parser Duplicate Handling Notes
Node.js dotenv Latter covers Most common mode
Python dotenv Latter covers Configurable to override system variables
PHP phpdotenv Default error Can be set to allow overrides
Ruby dotenv Latter covers Issues a warning
Go godotenv Latter covers No warning
Docker Compose Latter covers Follows file loading order

Append: maybe a Callable[[list[str]], str] like sum is also acceptable, for #374 suggests a customed merge logic.

Dominant language
Python
Stars
8.9k
Forks
581
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from theskumar/python-dotenv

All issues in theskumar/python-dotenv

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.