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

[BUG] Editor breaks when default is a json #272

Open
adityasule opened this issue Nov 8, 2022 · 2 comments
Open

[BUG] Editor breaks when default is a json #272

adityasule opened this issue Nov 8, 2022 · 2 comments
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@adityasule
Copy link

version: 2.10.0

When default value for editor is a json, the question cannot be rendered. Here is an example reproducing the error

Python 3.10.8 (main, Oct 13 2022, 10:17:43) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> import inquirer
>>> questions=[inquirer.Editor("test", "This is a Question", default=json.dumps({"foo": "bar"}))]
>>> inquirer.prompt(questions)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/name/.local/share/virtualenvs/rihqt8cC/lib/python3.10/site-packages/inquirer/prompt.py", line 11, in prompt
    answers[question.name] = render.render(question, answers)
  File "/Users/name/.local/share/virtualenvs/rihqt8cC/lib/python3.10/site-packages/inquirer/render/console/__init__.py", line 38, in render
    return self._event_loop(render)
  File "/Users/name/.local/share/virtualenvs/rihqt8cC/lib/python3.10/site-packages/inquirer/render/console/__init__.py", line 48, in _event_loop
    self._print_header(render)
  File "/Users/name/.local/share/virtualenvs/rihqt8cC/lib/python3.10/site-packages/inquirer/render/console/__init__.py", line 76, in _print_header
    default=render.question.default, color=self._theme.Question.default_color, normal=self.terminal.normal
  File "/Users/name/.local/share/virtualenvs/rihqt8cC/lib/python3.10/site-packages/inquirer/questions.py", line 55, in default
    return self.answers.get(self.name) or self._solve(self._default)
  File "/Users/name/.local/share/virtualenvs/rihqt8cC/lib/python3.10/site-packages/inquirer/questions.py", line 80, in _solve
    return prop.format(**self.answers)
KeyError: '"foo"'
>>>
@Cube707 Cube707 self-assigned this Nov 11, 2022
@Cube707
Copy link
Collaborator

Cube707 commented Nov 11, 2022

this stems from the fact that default will be stringifyed uppon Object-creation and than on rendering get a .format() applyed to it. This failes with json strings, as they contain curly brackets, which are interpreted for formating.

No reals solution to this right now

@Cube707 Cube707 removed their assignment Nov 11, 2022
@Cube707 Cube707 added bug Something isn't working wontfix This will not be worked on labels Dec 18, 2022
@XDGFX
Copy link

XDGFX commented Dec 31, 2022

You might be able to escape the curly brackets by doubling them up as mentioned here. Alternatively, that response suggests using string.Template which might be a good alternative?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants