[DockerComposeConfigurator] Fix duplicate top-level key on reconfigure#1090
Merged
nicolas-grekas merged 1 commit intoMay 29, 2026
Merged
Conversation
4c18fc2 to
ec6489a
Compare
ec6489a to
3446c0f
Compare
Member
|
Thank you @mistyfiky. |
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.
Problem
composer recipes:install --reset --force(or any re-invocation ofconfigureagainst an already-markedcompose.yaml) can produce a duplicate top-level key:docker compose configthen rejects the file withmapping key "volumes" already defined.Triggered when a recipe touches a non-last top-level section (e.g.
symfony/mailercontributing onlyservices:on a file that already hasvolumes:) and that recipe's markers are already present.Root cause
Two interacting bugs in
DockerComposeConfigurator::configureDockerCompose. Either alone is harmless; the duplicate top-level key requires both.$nodesLinesaccounting. The parser appends each line to$nodesLines[$node]before checking whether the line itself starts a new top-level key. So when the loop reachesvolumes:, that header is recorded under the outgoingservicesnode. Whenservicesis later updated and spliced back, the replacement carries a trailingvolumes:; the originalvolumes:header sits one index past the splice range and survives — duplicate.Position-adjustment math. After the in-place splice,
$startAt/$endAtfor later sections are adjusted by-$length - 1and-$lengthrespectively. The correct shift is-($length - 1).Why they mask each other. Fix only the accounting bug and the next section's splice (with the off-by-two
startAt) deletes that section's header. Fix only the math and the leftover key compounds — three consecutivevolumes:lines. Together, the splice range matches what$nodesLines[old node]mirrors, and subsequent sections land at correct positions.Fix
$nodesLines[$node][$i](plus[$i - 1]if the previous line was blank) so recorded content matches the splice range[startAt..endAt-1].$shift = $length - 1for both$startAtand$endAtadjustments.Test
testReconfigureDoesNotDuplicateLaterTopLevelKey— fails on2.x, passes here.