-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Breaking change in environment variable configuration prefix support in dotnet 6 #61577
Comments
Tagging subscribers to this area: @maryamariyan, @safern Issue DetailsDescriptionWhen using environment variable configuration, the prefix is no longer normalized like it was in dotnet 5.0. As the environment variable prefix should contain Reproduction Steps
Expected behaviorIt should print Actual behaviorIt prints Regression?This works in dotnet 5.0. Known WorkaroundsChanging the prefix to use eg, if I change the line Configuration.NET version: 6.0.100 Other informationIt appears that 9a322a5 changed the behavior as part of #42932 while trying to fix #40911.
|
existing test was changed in #42932 but there is no indication of this breaking behavior in https://docs.microsoft.com/en-us/dotnet/core/compatibility/6.0. new behavior ("what you see is what you get" without special case) makes more sense, but should be mentioned in compatibility docs. |
When I originally introduced the PR (around core 3.x, prior to 5.0 release), the prefix normalization wasn't documented (or at least not in a place where it should've been). I thusly considered this a bug. When I raised the issue, there was no objection to that statement. Since documentation wasn't clear on that subject, I considered the prefix normalization to be a bug. I therefore changed the behaviour to normalize variables only. The PR was stuck in review for close to 4 months, and ultimately got a green light, which leads me to believe my interpretation was correct. I don't mean this as an attack or anything of this sort, I'm simply stating my perspective. If I indeed caused a regression - I apologize. Regarding #61577 (comment): that is an accidental mistake; while my memory doesn't go this far, I don't think it was my intention to modify tests. I've no idea why this particular test was changed. |
as a user, in .net 5 there was a different kind of special casing, in .net 6 it's still special casing (breaking .net 5 guarantees). if it's my call, i'd remove all special casing and magic from this type and keep it simple. that kind of breaking change would be well received. |
Isn't that (almost) what we have right now? Prefix has no indication for special characters, so it's taken literally. Previously, processing did normalize -> filter + strip -> process. My PR inverted the first 2 steps; now it's filter + strip (literal) -> normalize -> process. As for stripped variable names, Configuration uses The gist of the PR was that if you had an envvar like Under previous behaviour, if you used consistent envvar naming across platforms ( The documentation mentions normalization, but it does not explicitly say whether this includes the prefix or not; all that is mentioned about it is that it's stripped. You have a gap for interpretation: is the filtered input normalized, or is the normalized input filtered? In short, I believe the issue stems from ambiguity. What needs to be decided is which interpretation is canonical. |
yes, your pr is improvement as i mentioned above. but still if we don't canonicalize it ( |
cc @HaoK what is your take on this? |
My quick take is that it seems like a breaking change that should be reverted |
I think while the chance is low, the potential damage is higher, and that this is a more severe breaking change, because it can be completely silent. I think someone is going to update, everything is going to appear fine, but when they deploy it to production it is going to not override some of the settings. The program could run for a long time, and cause a lot of damage, before anybody notices it's not doing what it's supposed to do. |
So we are looking to revert it back to old behavior, seems like since we didn't advertise the bugfix in breaking change docs it is unlikely to cause problem if we regress it back. and to mitigate and reduce ambiguity it would also be worth updating tests or adding docs. |
reopening as this needs to be ported to release/6.0 |
We are looking to definitely fix this regression in our next 6.0 servicing release (#62916) and plan on adding a breaking change notification to communicate the change as well. The fix involves reverting the original bug fix for underlying issue #42932 as it seemed to be in conflict with existing behavior. The workaround would be to replace double underscore in prefix with Wanted to also circle back with @Emzi0767 again as PR author of #42932, to make sure this decision would not block you. |
There's nothing on my end. I think that an explicit note documenting this should be added to documentation somewhere however, so we can avoid future confusion and problems. |
It appears this has been fixed in |
Here's the PR that got serviced in 6.0.2: #62916 |
EDIT: I missed this post on my earlier run through which explains this breaking change was intended: #61577 (comment) but I still wish to suggest that I believe all issues can be resolved satisfactorily. As mentioned in the above comment, this 6.0.2 fix also has a hidden breaking change (bug?) from 6.0.0 and 6.0.1, and has broken a number of our production builds. I'll document my findings and suggested workarounds / fixes below in more detail for anyone else suffering from this problem. SummaryPrefixes which happen to contain EG configuration which is set up with BackgroundWe automatically pulled in the 6.0.2 docker image patch release via the default 6.0 tag. 6.0.2 is a security patch fixing CVE-2022-21986 - it's unfortunate having a breaking change in a patch version, but these things happen. DetailsIn particular, the following now fails after pulling in a 6.0.2 patch release of the dotnet runtime:
There is nothing in the documentation to suggest Side note - I'm not quite sure what this test means by "Won't Normalise" in terms of expected behaviour - it seems to be asserting that this bug occurs, but maybe I'm missing an intended behaviour? Proposed changesI'd like to propose that, the following changes are made:
Proposed workaroundIn the This will enable you updating the app to work with existing configuration:
|
The behaviour you're describing is the original, intended, and undocumented behaviour. This revert fix reverted a change which addressed that. It's unlikely to be changed. |
I'm struggling a little to understand the motivation for this prefix not matching being intended behaviour? If it is, I feel it should be documented. It appears all the various bug reports stem from things not matching when they should (because the code in its various formulations has ended up comparing a normalised prefix against an unnormalised key or vice versa, or compared an unnormalized prefix and key when a normalized comparison was required). If the code ensured the comparison / filtering is either comparing normalized prefixes to normalized prefixes or unnormalized prefixes to unnormalized prefixes, I believe all bugs / confusing behaviours can be resolved simultaneously / satisfactorily. I'm happy to stick in a PR to demonstrate this. |
FYI the breaking change doc related to this issue is getting added in dotnet/docs#31742 |
Description
When using environment variable configuration, the prefix is no longer normalized like it was in dotnet 5.0.
As the environment variable prefix should contain
:
if on Windows, and__
if on Linux, then normalizing the prefix makes sense to me. Otherwise, I have to duplicate the OS detection/normalization code myself.Reproduction Steps
Microsoft.Extensions.Configuration
,Microsoft.Extensions.Configuration.Binder
andMicrosoft.Extensions.Configuration.EnvironmentVariables
ConsoleApp1__Foo=42
Expected behavior
It should print
42
Actual behavior
It prints
<null>
Regression?
This works in dotnet 5.0.
Known Workarounds
Changing the prefix to use
__
instead of:
works:eg, if I change the line
var environmentOverridesPrefix = typeof(Program).Namespace!.Replace(".", ":") + ":";
to
var environmentOverridesPrefix = typeof(Program).Namespace!.Replace(".", "__") + "__";
it works
Configuration
.NET version: 6.0.100
OS: Windows 11, 21H2 (OS Build 22000.346)
Arch: x64
Platform specific: no, we were facing it on linux as well
Other information
It appears that 9a322a5 changed the behavior as part of #42932 while trying to fix #40911.
The text was updated successfully, but these errors were encountered: