question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jinja "[[ x ]]" in the default of a parameter y always reuses x's default (if it exists) regardless of user input to x

See original GitHub issue

In v6.0.0-a.5, the following copier.yml always renders email’s default prompt as foo@example.com regardless of the input to the username and organization variables. In v5.1.0, email default prompt was based on the input to the username and organization variables.

# default
username:
    type: str
    default: "foo"

organization:
    type: str
    default: "example"

email:
    type: str
    # Notice that both `username` and `organization` have been already asked
    default: "[[ username ]]@[[ organization ]].com"

Additionally, if the default of organization is also a jinja template, emails default will not use the rendered organization default value.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewleechcommented, Jun 11, 2021

Hi, I’ve run into this issue today testing a new setup with 6.0.0a6 With a really basic copier.yaml


username:
    type: str
    default: me

organization:
    type: str
    default: there

email:
    type: str
    # Notice that both `username` and `organization` have been already asked
    default: "[[ username ]]@[[ organization ]].com"

final:
    type: str
    # Notice that both `username` and `organization` have been already asked
    default: "Hello: [[ email ]]"

Running this without overriding the defaults results in expected behavior, until the template of a template:

anl@STEP:~/test$ copier ../template .

No git tags found in template; using HEAD as ref
🎤 username? Format: str me
🎤 organization? Format: str there
🎤 email? Format: str me@there.com
🎤 final? Format: str Hello: [[ username ]]@[[ organization ]].com

However as reported, even when I overwrite the defaults at the prompt, they’re still used in the templated default:

anl@STEP:~/test$ copier ../template .

No git tags found in template; using HEAD as ref
🎤 username? Format: str foo
🎤 organization? Format: str bar
🎤 email? Format: str me@there.com
🎤 final? Format: str Hello: [[ username ]]@[[ organization ]].com

I had the same problem trying to use earlier variables in where: keys, the default is always provided by the variable, or None if no default is set.

0reactions
yajocommented, Jun 19, 2021

Thanks! Let’s consider it fixed then. Please reopen otherwise.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jinja2 template variable if None Object set a default value
This example uses the term "first_name" which we can assume will not expect a value of False , but there are many cases...
Read more >
Template Designer Documentation - Jinja
Template Designer Documentation¶. This document describes the syntax and semantics of the template engine and will be most useful as reference to those ......
Read more >
Jinja2 default() Test - OzNetNerd.com
This will output the value of my_variable if the variable was defined, otherwise 'my_variable is not defined'. If you want to use default...
Read more >
Setting a default value with Default - Sendwithus
Jinja has a built in default filter that can be used to set a default value ... parameter will return the default value...
Read more >
html - TOSCA Simple Profile in YAML Version 1.2 - OASIS Open
This document defines a simplified profile of the TOSCA version 1.0 specification in a YAML rendering which is intended to simplify the authoring...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found