[BugFix] Preserve Required flag for duplicate interpolation variables#863
Open
Cursx wants to merge 1 commit intocompose-spec:mainfrom
Open
[BugFix] Preserve Required flag for duplicate interpolation variables#863Cursx wants to merge 1 commit intocompose-spec:mainfrom
Cursx wants to merge 1 commit intocompose-spec:mainfrom
Conversation
23940f0 to
c8151d1
Compare
…Issue docker/compose#13718) Signed-off-by: Cursx <33718736+Cursx@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes docker/compose#13718 —
template.ExtractVariablesnow correctly aggregatesRequired=trueconstraints when an interpolation variable is referenced multiple times.When a Compose configuration utilizes the same variable name using both required and optional notations (e.g.,
${PIHOLE_DOMAIN:?}followed by${PIHOLE_DOMAIN}), the parser previously overwrote the element completely. This caused the variable mapping to silently drop the stringency requirement (Required: false), leadingdocker compose config --variablesto misreport requirement constraints. This patch introduces amergeVariablefunction implementing a logicalORfor theRequiredflag and mergesDefaultValue/PresenceValueattributes safely.Before
Running
docker compose config --variables --format jsonmistakenly prints:{ "PIHOLE_DOMAIN": { "Name": "PIHOLE_DOMAIN", "Required": false } }After
With
mergeVariablecorrectly aggregating constraints, runningdocker compose config --variables --format jsonaccurately respects the strictest condition anywhere in the file:{ "PIHOLE_DOMAIN": { "Name": "PIHOLE_DOMAIN", "Required": true } }Users are now correctly warned about missing required variables in pre-flight Compose validations, regardless of YAML declaration order.
Test results (18 passed)
Test plan
duplicate-variable-required-preserved,duplicate-variable-value-preserved,duplicate-variable-in-map,duplicate-variable-in-string, andduplicate-variable-conflict-default-requiredyielding combinedRequired: truebehavior and cascading default values without data loss across all AST node types.