Skip to content

Commit

Permalink
Fixes failing formatting of DAG file containing {} in docstring (#9779)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 43cb059e96dda850aae6f6666c518f2b2ae22faa
  • Loading branch information
potiuk authored and Cloud Composer Team committed Sep 12, 2024
1 parent b61dafc commit dbe9a36
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions airflow/www/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ def wrapped_markdown(s, css_class=None):
return None

return Markup(
'<div class="rich_doc {css_class}" >' + markdown.markdown(s) + "</div>"
).format(css_class=css_class)
'<div class="rich_doc {css_class}" >'.format(css_class=css_class) + markdown.markdown(s) + "</div>"
)


def get_attr_renderer():
Expand Down
14 changes: 14 additions & 0 deletions tests/www/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from parameterized import parameterized

from airflow.www import utils
from airflow.www.utils import wrapped_markdown
from tests.test_utils.config import conf_vars


Expand Down Expand Up @@ -229,3 +230,16 @@ def test_markdown(self):
def test_markdown_none(self):
rendered = self.attr_renderer["python_callable"](None)
self.assertEqual("", rendered)


class TestWrappedMarkdown(unittest.TestCase):

def test_wrapped_markdown_with_docstring_curly_braces(self):
rendered = wrapped_markdown("{braces}", css_class="a_class")
self.assertEqual('<div class="rich_doc a_class" ><p>{braces}</p></div>', rendered)

def test_wrapped_markdown_with_some_markdown(self):
rendered = wrapped_markdown("*italic*\n**bold**\n", css_class="a_class")
self.assertEqual(
'''<div class="rich_doc a_class" ><p><em>italic</em>
<strong>bold</strong></p></div>''', rendered)

0 comments on commit dbe9a36

Please sign in to comment.