Feature Request: Exception or Warning on Duplicate Configuration Items

未关闭
#591 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
devops

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
8.9k
派生
581
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

theskumar/python-dotenv 的其他 Issue

查看 theskumar/python-dotenv 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。