Fix recursive context overwrites#1961
Merged
ericof merged 5 commits intocookiecutter:mainfrom Nov 9, 2023
Merged
Conversation
The recursive call to apply_overwrites_to_context for dictionary variables mistakenly led to lists in dictionaries being treated as choice/multichoice variables
for more information, see https://pre-commit.ci
…-padraic/cookiecutter into fix_recursive_context_overwrites
Contributor
Author
|
Hello, just a nudge to ask if this could be reviewed? At the moment I'm running off my own branch as this issue is blocking us from using the main cookiecutter release |
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.
In 2.2.0,
generate.apply_overwrites_to_contextwas amended with a recursive call to allow merging fields inside dictionary variables (#1692 )In 2.3.0, it was further amended to allow merging of multichoice variables (#1903).
However, these two changes interact to mean that cookiecutter began treating any list field in a dictionary variable as a choice (see #1954, #1960 for bugs running into this issue). If all the entries in a list field are hashable, then this may not cause problems, but if e.g. you have complex objects with lists of dictionary variables then the call to set introduce in #1903 would also cause a crash.
This PR fixes the merge behaviour by adding a simple recursive flag when applying the overwrites to dictionary variables. Cookiecutter itself will only treat "top-level" lists as choice variables, so this is consistent with the interaction model and the docs which state "The dictionary values can, themselves, be other dictionaries and lists - the data structure can be as deep as you need."