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
Variable with null default no longer being required #1919
Comments
w-biggs
changed the title
Variable with null default not required
Variable with null default not being required
Aug 11, 2023
w-biggs
changed the title
Variable with null default not being required
Variable with null default no longer being required
Aug 11, 2023
Managed to replicate. I guess, a simple solution would be something like:
def read_user_variable(var_name, default_value, prompts=None, prefix=""):
question = (
prompts[var_name]
if prompts and var_name in prompts.keys() and prompts[var_name]
else var_name
)
# Ask until the valid answer is provided
while (
variable := Prompt.ask(f"{prefix}{question}", default=default_value)
) is None:
pass
return variable Although, I don't know whether you guys are okay with walrus operator. A simple Can I take the issue? UPD:
|
limtis0
added a commit
to limtis0/cookiecutter
that referenced
this issue
Aug 13, 2023
ericof
pushed a commit
that referenced
this issue
Sep 21, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description:
After updating from 2.1.1 to 2.3.0, setting a field's default value in
cookiecutter.json
tonull
no longer makes that field required. It instead passesNone
as the value of that variable. Previously, it would repeat that prompt until you gave it a value.It looks like this happened in the switch from
click
torich
in 2.3.0 -click
doesn't allow a prompt without a default value to be empty (there's awhile True
loop), whilerich
does (it just casts the input and makes sure it doesn't cause a ValueError -- which it doesn't, asstr(None)=="None"
). It seems like, withrich
, you have to handle that logic yourself.What I've run:
An example (
component_name
's value isnull
,service_name
's istest
):Compare to output with version 2.1.1:
The text was updated successfully, but these errors were encountered: