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

Nested Questions Asked Incorrectly #1697

Open
davidbrownell opened this issue Jul 11, 2024 · 2 comments
Open

Nested Questions Asked Incorrectly #1697

davidbrownell opened this issue Jul 11, 2024 · 2 comments
Labels
bug triage Trying to make sure if this is valid or not

Comments

@davidbrownell
Copy link

Describe the problem

I have a template with a choice of 2 values, where a different question should be asked based on the previous choice.

project_type:
  type: str
  choices:
    - One
    - Two

one_question:
  type: bool
  when: "{{ project_type == 'One' }}"
  default: False

two_question:
  type: bool
  when: "{{ project_type == 'Two' }}"
  default: False

In addition, an additional question should be asked if the response to one of the choice-specific questions was True:

one_nested:
  type: bool
  when: "{{ one_question }}"
  default: False

two_nested:
  type: bool
  when: "{{ two_question }}"
  default: False

Things work as expected when running copier copy... the first time around. However, when running copier copy... (on the same target directory) with a different choice, copier prompts for an answer to the original nested question in addition to the nested question associated with the new choice (this is clearer in the screenshots below).

Template

https://github.com/davidbrownell/copier-TemplateIssue

To Reproduce

  1. Run copier copy https://github.com/davidbrownell/copier-TemplateIssue <output_dir>
  2. Answer project_type: One, one_question: Y, one_nested: Y
  3. Run copier copy https://github.com/davidbrownell/copier-TemplateIssue <output_dir>
  4. Answer project_type: Two
  5. Note that you are prompted to answer one_nested even though one_question has defaulted to False.

Logs

No response

Expected behavior

one-related questions should not be asked when the project_type is set to Two.

Screenshots/screencasts/logs

image

Operating system

Windows

Operating system distribution and version

Windows 11

Copier version

copier 9.3.1

Python version

CPython 3.12

Installation method

pip+pypi

Additional context

No response

@davidbrownell davidbrownell added bug triage Trying to make sure if this is valid or not labels Jul 11, 2024
@yajo
Copy link
Member

yajo commented Jul 12, 2024

That's probably because it's getting the answer from the last update. Try with this:

one_nested:
  type: bool
  when: "{{ project_type == 'One' and one_question }}"
  default: False

two_nested:
  type: bool
  when: "{{ project_type == 'Two' and two_question }}"
  default: False

@pawamoy
Copy link
Contributor

pawamoy commented Jul 12, 2024

That's probably because it's getting the answer from the last update.

That's what I suspected too. Does that make sense though? Shouldn't we have recopy do this only, and not copy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Trying to make sure if this is valid or not
Projects
None yet
Development

No branches or pull requests

3 participants