-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix(core): context value for feature flag should be parsed for boolean #34616
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
base: main
Are you sure you want to change the base?
Conversation
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.
The pull request linter fails with the following errors:
❌ Fixes must contain a change to an integration test file and the resulting snapshot.
If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed, add Clarification Request
to a comment.
✅ A exemption request has been requested. Please wait for a maintainer's review.
Exemption Request: This change correctly parses feature flag and has been validated through unit tests; Also existing integration tests were successfully executed; additional integration test should not be needed. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Is it possible to ensure that the boolean feature flags are always specified as booleans instead of strings? This would resolve the issue at its source. |
While it would be ideal to ensure feature flags are always specified as booleans, there could be couple of challenges:
This fix takes a pragmatic approach by handling string representations properly while maintaining backward compatibility, to addresses the immediate issue without disrupting existing workflows. |
I would argue that a new integ is needed, having no test is what lead to #30583. Plus since you are introducing a new feature flag, an integ that at least tests with the ff enabled and disabled should be created (usually enabled and disabled ff is also applied to the existing tests if applicable too). I understand what you are saying about the unit test, but a unit test is exactly that, just a unit test, integ tests ensure that your change is able to be deployed to cfn. |
Thank you for the feedback. I would like to call out that this PR doesn’t introduce any new feature flag; it only fixes how existing flags are parsed when passed as a string. The issue in #30583 occurred precisely because existing integration tests were failing due to incorrect parsing of string feature flag values; these integration tests cover resources with feature flags both enabled and disabled. |
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.
I'm with Vishaal. This issue should be addressed where the flag value is set, not where it is read.
Please point me to where is this specific "false"
value is coming from?
- Yes, the CLI only allows passing string context. That was a pragmatic decision 5 years ago, and until now no-one has complained they weren't able to pass booleans via the CLI. We can still fix it, but it must not be that important if nobody has complained in 5 years.
- Other context sources are represented in JSON, so are perfectly capable of representing the distiction between
"false"
andfalse
.
If the "false"
is coming from our code base, I'd rather have a linter check saying "this value looks supiciously like a stringified boolean, are you sure that's what you mean?"
I agree with that! However you're also making an assumption here 🤓. Not your change, but do we actually have integ tests for both flag values? |
Here's where the "false" is coming from: If I understand correctly, CLI’s entire context-passing mechanism relies on serialising every entry to a |
We do have integ tests where the flag values are picked from the recommended-feature-flags and the recommended values have both true and false; one such flag being logApiResponseDataPropertyTrueDefault where the flag value is being passed 'false' for the integration tests. |
This is an excellent summary and investigation! Thank you. Sounds like it is pretty much the feature that @rix0rrr was pointing out:
To me, we should fix this issue. It will not only be an issue for us but for others as well. I don't think detecting numbers and booleans and correctly typing them would be highly controversial or backward incompatible. But I can appreciate that it goes beyond the immediate problem and how a more "hacky" solution could be more appropriate. What do you both think? |
I agree that this is worth fixing, but for this PR I was leaning towards fixing the immediate problem keeping the CLI behaviour consistent. I can follow up in a separate PR for having first‐class support for typed context values. The potential solution for fixing this could be patching the
This should retain the type of context value as |
Parameters are something entirely different. you are looking for this function: https://github.com/aws/aws-cdk-cli/blob/main/packages/aws-cdk/lib/cli/user-configuration.ts#L332 |
Thank you for the reference; I have created the PR for supporting the typed context values: aws/aws-cdk-cli#595 |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #30583.
Reason for this change
Integration tests fail when feature flag snapshots are incorrectly updated to
true
for flags defaulted tofalse
when they are being passed as string values.Description of changes
Fixed an issue where feature flags are incorrectly computed when passed as the string value 'false'.
The current implementation uses
Boolean('false')
which evaluates totrue
here; this caused integration test snapshots to be updated with incorrect values (true
) for feature flags that should default tofalse
.This change properly parses string representations of boolean values to ensure feature flags maintain their intended state, resolving the integration test failures.
Description of how you validated changes
false
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license