-
-
Notifications
You must be signed in to change notification settings - Fork 145
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
fix(bug): prefix config environment vars to avoid conflicts #2479
Conversation
This feature is not documented anywhere, so we should probably add it to the config guide. I kind of like it under the line:
Something like:
|
So I tried to see if I could use I had to change:
to
At that point I can add a test:
|
OK, let me do that, will get back to you shortly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had an issue planning to do this, thanks for taking it up!
Maintainer note: Breaking change for 0.9
I am arguing against this for a couple reasons. |
Fair enough! Agree with releasing as a patch update Documentation can be updated in a later PR |
@antazoey , please check the latest version, it includes tests and docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing! Thank you so much. I think we can take it from here, just a few nits I can address and then merge.
What I did
The configuration classes (e.g.
ape_ethereum.NetworkConfig
orape_test.CoverageReportsConfig
) incorrectly interpret environment variables as part of their own settings.For example there are
terminal
andhtml
fields inCoverageReportsConfig
:Now, if you try running
ape
with one of those (somewhat common) names set as an environment variable, it will either crash or, even worse, run with one of its settings likely augmented without the user ever intending it.The reason for this behaviour is that the
pydantic-settings
module searches for environment variables of the same name as each setting: https://docs.pydantic.dev/latest/concepts/pydantic_settings/#environment-variable-namesI couldn't find a way to disable the environment variable settings.
To solve the problem, this patch introduces the following prefixes based on their root module:
APE_
APE_CACHE_
APE_COMPILE_
APE_CONSOLE_
APE_ETHEREUM_
APE_NETWORKS_
APE_NODE_
APE_TEST_
The following config classes are affected:
Thus the previously used as an example
TERMINAL
environment variable now becomesAPE_TEST_TERMINAL
. The same applies respectively to all other settings as well.This patch carries the risk of invalidating the settings of users who rely on environment variables based configuration (even though this seems highly unlikely), so make sure to include it in the changelog as a breaking change, should this patch get approved.