Skip to content
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(core): Remove useless entries from Stage.context #3359

Merged
merged 4 commits into from
Jan 21, 2020

Conversation

pdelagrave
Copy link

Fixes spinnaker/spinnaker#5257

The Stage constructor was keeping refId, startTimeExpiry and requisiteStageRefIds from the context map argument in its internal context map. This caused issues when a parent stage's context was used to create a child stage, as these entries aren't expected to be inherited. This wasn't a problem for a long time because these values were accidentally removed by the side effect of StartStageHandler#shouldSkip. shouldSkip() uses objectMapper.convertValue() on a stage context expecting to have a cloned map returned. A long standing design/documentation issue with Jackson made convertValue() return the input parameter as is instead of converting/cloning it. This made every Stage passing through StartStageHandler.handle() having their context map indirectly 'corrected' and persisted.
An upcoming upgrade to Spring Boot 2.2 comes with Jackson 2.10 where objectMapper.convertValue() has a new behaviour and would make shouldSkip() fail to silently 'correct' the stages context map.
FasterXML/jackson-databind#2220

BakeStageSpec was validating context['refId'] on the generated contexts but the contexts aren't Stages yet; once a context is made into a Stage and added to the graph (graph.add) it will have its refId generated based on the parent refId; which isn't under test in that spec.

Fixes spinnaker/spinnaker#5257

The `Stage` constructor was keeping `refId`, `startTimeExpiry` and `requisiteStageRefIds` from the context map argument in its internal context map. This caused issues when a parent stage's context was used to create a child stage, as these entries aren't expected to be inherited. This wasn't a problem for a long time because these values were accidentally removed by the side effect of `StartStageHandler#shouldSkip`. `shouldSkip()` uses `objectMapper.convertValue()` on a stage context expecting to have a cloned map returned. A long standing design/documentation issue with Jackson made `convertValue()` return the input parameter as is instead of converting/cloning it. This made every `Stage` passing through `StartStageHandler.handle()` having their context map indirectly 'corrected' and persisted.
An upcoming upgrade to Spring Boot 2.2 comes with Jackson 2.10 where `objectMapper.convertValue()` has a new behaviour and would make `shouldSkip()` fail to silently 'correct' the stages context map.
FasterXML/jackson-databind#2220

`BakeStageSpec` was validating `context['refId']` on the generated contexts but the contexts aren't Stages yet; once a context is made into a Stage and added to the graph (`graph.add`) it will have its `refId` generated based on the parent refId; which isn't under test in that spec.
@pdelagrave
Copy link
Author

@robzienert @robfletcher

@@ -114,6 +113,8 @@ public Stage(Execution execution, String type, String name, Map<String, Object>
this.requisiteStageRefIds =
Optional.ofNullable((Collection<String>) context.remove("requisiteStageRefIds"))
.orElse(emptySet());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole function seems suspect to me (i've looked into this before but ran into some issues trying to fix it - don't recall what they were)
the context this function receives as the param is passed by ref so we actually modify the context from the caller which is a bit messed up.
but AFAIR there were no calls to this that mattered so i sort of put it aside...
anyway, the change LGTM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is passed by reference, shouldn't a stage copy the context? Would we need to do a deep copy or would a copy of the map only be sufficient?

@robzienert robzienert added the ready to merge Approved and ready for merge label Jan 21, 2020
@mergify mergify bot added the auto merged Merged automatically by a bot label Jan 21, 2020
@mergify mergify bot merged commit df10b3c into spinnaker:master Jan 21, 2020
KathrynLewis pushed a commit to KathrynLewis/orca that referenced this pull request Jan 31, 2021
Fixes spinnaker/spinnaker#5257

The `Stage` constructor was keeping `refId`, `startTimeExpiry` and `requisiteStageRefIds` from the context map argument in its internal context map. This caused issues when a parent stage's context was used to create a child stage, as these entries aren't expected to be inherited. This wasn't a problem for a long time because these values were accidentally removed by the side effect of `StartStageHandler#shouldSkip`. `shouldSkip()` uses `objectMapper.convertValue()` on a stage context expecting to have a cloned map returned. A long standing design/documentation issue with Jackson made `convertValue()` return the input parameter as is instead of converting/cloning it. This made every `Stage` passing through `StartStageHandler.handle()` having their context map indirectly 'corrected' and persisted.
An upcoming upgrade to Spring Boot 2.2 comes with Jackson 2.10 where `objectMapper.convertValue()` has a new behaviour and would make `shouldSkip()` fail to silently 'correct' the stages context map.
FasterXML/jackson-databind#2220

`BakeStageSpec` was validating `context['refId']` on the generated contexts but the contexts aren't Stages yet; once a context is made into a Stage and added to the graph (`graph.add`) it will have its `refId` generated based on the parent refId; which isn't under test in that spec.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto merged Merged automatically by a bot ready to merge Approved and ready for merge target-release/1.19
Projects
None yet
4 participants