Skip to content

Fix recursive context overwrites#1961

Merged
ericof merged 5 commits intocookiecutter:mainfrom
padraic-padraic:fix_recursive_context_overwrites
Nov 9, 2023
Merged

Fix recursive context overwrites#1961
ericof merged 5 commits intocookiecutter:mainfrom
padraic-padraic:fix_recursive_context_overwrites

Conversation

@padraic-padraic
Copy link
Copy Markdown
Contributor

In 2.2.0, generate.apply_overwrites_to_context was 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."

Padraic Calpin and others added 5 commits October 16, 2023 11:45
The recursive call to apply_overwrites_to_context for dictionary
variables mistakenly led to lists in dictionaries being treated
as choice/multichoice variables
…-padraic/cookiecutter into fix_recursive_context_overwrites
@padraic-padraic
Copy link
Copy Markdown
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

@ericof ericof self-requested a review November 9, 2023 18:39
@ericof ericof added the bug This issue/PR relates to a bug. label Nov 9, 2023
Copy link
Copy Markdown
Member

@ericof ericof left a comment

Choose a reason for hiding this comment

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

Thanks for the fix

@ericof ericof merged commit 5944d0f into cookiecutter:main Nov 9, 2023
@padraic-padraic padraic-padraic deleted the fix_recursive_context_overwrites branch December 4, 2023 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This issue/PR relates to a bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants