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.

dictionary variables defined in cookiecutter.json erroring on manual run and templates in context values not working

See original GitHub issue
  • Cookiecutter version: 1.7.3
  • Template project url: n/a
  • Python version: 3.9.0
  • Operating System: Windows 10

Description:

Fresh install of cookiecutter. When I run the template, I have a default set of defined variables in the cookiecutter.json file, one of which is supposed to be a hidden dictionary variable that the outputs use to lookup what to use in the output file. The problem is it still asks for input to this “hidden” variable as [default] and then errors when I press enter saying “Error: Unable to decode to JSON.” I do not have this issue when executing on my Mac with cookiecutter version 1.6.0. Also if I run the template with the --no-input flag it works fine but the problem then is the variables that I need the user to change from default arent changed because they of course do not get the prompt. Also I am using a template in the context values to set another hidden variable but it also does not work. The output contains the bracketed text as a whole in the output (not the value of the variable I expect). So in my example below, in the output file I get “{{ cookiecutter.olt” and I would expect to get BNG.

What I’ve run:

cookiecutter.json

{
  "olt": "BNGOLT4",
 <snip>
  "_shelter": "{{ cookiecutter.olt[:3] }}",
  "_drPair": {
    "Lab": {
      "dr1": "LABDR1",
      "dr2": "LABDR2"
    },
    "3": {
      "dr1": "CODDR3",
      "dr2": "FABDR3"
    },
    "4": {
      "dr1": "CODDR4",
      "dr2": "FADDR4"
    }
  }
}

JSON error

$ cookiecutter testTemplate
olt [BNGOLT4]:
<snip>
_drPair [default]:
Error: Unable to decode to JSON.
_drPair [default]:
Error: Unable to decode to JSON.
_drPair [default]:
Error: Unable to decode to JSON.
_drPair [default]:

-v output of the default value of _drPair in cookiecutter.json

('_drPair', OrderedDict([('Lab', OrderedDict([('dr1', 'LABDR1'), ('dr2', 'LABDR2')])), ('3', OrderedDict([('dr1', 'CODDR3'), ('dr2', 'FADDR3')])), ('4', OrderedDict([('dr1', 'CODDR4'), ('dr2', 'FADDR4')])

Screenshot of the invalid output of the _shelter variable not pulling the defined value earlier: SS 2021-07-06 09 27 48

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cjolowiczcommented, Jul 20, 2021

The follow-up issue with JSON not being decoded was fixed in #1562, which is also still unreleased. pip install cookiecutter 'click<8' would work around this one.

0reactions
cjolowiczcommented, Jul 20, 2021

I’m not the right person to answer that. @simobasso @ssbarnea @SharpEdgeMarshall might know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dictionary Variables (1.5+) — cookiecutter 1.7.0 documentation
Dictionary variables are, as the name suggests, dictionaries of key-value pairs. The dictionary values can, themselves, be other dictionaries and lists ...
Read more >
latest PDF - CKAN documentation
This user guide covers using CKAN's web interface to organize, publish and find data. CKAN also has a powerful API. (machine interface), which...
Read more >
NetLogo 6.3.0 User Manual
Can I run NetLogo from the command line, without the GUI? ... I'm varying a global variable I declared in the Code tab,...
Read more >
Django Design Patterns and Best Practices
Problem details. Django templates can only show variables that are present in its context dictionary. However, sites need the same information in several ......
Read more >
Untitled
Schematy word, Color run video music, Bantersaurus definition. ... Srikar reddy chicago, Mabentang gulay, Tds 26q return, Insight cable remote not working, ...
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