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

string templated fields are not rendered literally #14543

Closed
YangMuye opened this issue Mar 1, 2021 · 4 comments · Fixed by #15130
Closed

string templated fields are not rendered literally #14543

YangMuye opened this issue Mar 1, 2021 · 4 comments · Fixed by #15130
Labels
affected_version:2.0 Issues Reported for 2.0 area:UI Related to UI/UX. For Frontend Developers. good first issue kind:bug This is a clearly a bug
Milestone

Comments

@YangMuye
Copy link

YangMuye commented Mar 1, 2021

Apache Airflow version: 2.0.1

Kubernetes version (if you are using kubernetes) (use kubectl version): n/a

Environment:

  • Cloud provider or hardware configuration:
  • OS (e.g. from /etc/os-release): redhat 7.9
  • Kernel (e.g. uname -a): 3.10.0-1160.11.1.el7.x86_64
  • Install tools: pip
  • Others:

What happened:

Given the following code

SSHOperator(task_id='dummy', command='''\
for i in 1..100
do
echo $i
echo $i $i
echo $i $i $i
done
''')

The command field is rendered as:

'\n\nfor i in 1..100\ndo\necho $i\necho $i $i\necho $i $i $i\ndone\n'

What you expected to happen:

I expect to see

for i in 1..100
do
echo $i
echo $i $i
echo $i $i $i
done

How to reproduce it:

Anything else we need to know:

This is because the following line renders templated fields using the pformat function.

html_dict[template_field] = Markup("<pre><code>{}</pre></code>").format(
pformat(content)
) # noqa

I suggest we should render strings as is.

            if renderer in renderers:
                html_dict[template_field] = renderers[renderer](content)
            else:
                html_dict[template_field] = Markup("<pre><code>{}</pre></code>").format(
                     pformat(content)
+                   content if isinstance(content, str) else pformat(content)
                )  # noqa
@YangMuye YangMuye added the kind:bug This is a clearly a bug label Mar 1, 2021
@YangMuye YangMuye changed the title string templated fields are rendered literally string templated fields are not rendered literally Mar 1, 2021
@eladkal eladkal added area:UI Related to UI/UX. For Frontend Developers. affected_version:2.0 Issues Reported for 2.0 labels Mar 3, 2021
@eladkal
Copy link
Contributor

eladkal commented Mar 3, 2021

@YangMuye can you submit a PR with your suggest fix?

@jyotidhiman0610
Copy link
Contributor

Let me know if you are working on this @YangMuye, if not I can take this up.

@YangMuye
Copy link
Author

YangMuye commented Mar 6, 2021

@jyotidhiman0610 Sorry, I am not working on it. Please feel free to take this up.

@kaxil kaxil added this to the Airflow 2.0.2 milestone Mar 12, 2021
@uranusjr
Copy link
Member

uranusjr commented Apr 1, 2021

#15130 will fix this (by assigning the bash renderer to command).

kaxil pushed a commit that referenced this issue Apr 2, 2021
See #11177. Mostly SQL fields and Python options. Two notable execeptions:

* `WinRMOperator.command` is marked as a new renderer `powershell`.
* A new `jinja` renderer is implemented. The Pygment lexer is called `DjangoLexer`, but [Pygments suggets rendering Jinja2 with it](https://pygments.org/docs/lexers/#pygments.lexers.templates.DjangoLexer).

Fix #14543.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected_version:2.0 Issues Reported for 2.0 area:UI Related to UI/UX. For Frontend Developers. good first issue kind:bug This is a clearly a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants