Skip to content

Commit ebfd8f6

Browse files
committed
fix(dbt): return lists and scalars from fromyaml
The fromyaml builtin wrapped the parsed document in dict(), so YAML whose top level is not a mapping was mishandled: a block-style list raised an uncaught ValueError, and a flow-style list or a scalar was silently returned as None. dbt returns the parsed value as is. sqlmesh.utils.yaml.load already returns plain Python objects, so return its result directly. Mappings are unaffected. Fixes #6137 Signed-off-by: JanakiRamChittineni <341781521+raams95@users.noreply.github.com>
1 parent cc8d8b0 commit ebfd8f6

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

‎sqlmesh/dbt/builtin.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def to_yaml(value: t.Any, default: t.Optional[t.Any] = None) -> t.Optional[t.Any
369369

370370
def from_yaml(value: t.Any, default: t.Optional[t.Any] = None) -> t.Optional[t.Any]:
371371
try:
372-
return dict(yaml.load(value, raise_if_empty=False, render_jinja=False))
372+
return yaml.load(value, raise_if_empty=False, render_jinja=False)
373373
except (TypeError, YAMLError):
374374
return default
375375

‎tests/dbt/test_transformation.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,12 @@ def test_yaml(sushi_test_project: Project):
17921792
assert context.render("{{ toyaml(invalid) }}", invalid=lambda: "") == "None"
17931793

17941794
assert context.render("""{{ fromyaml('key: value') }}""") == "{'key': 'value'}"
1795+
assert context.render("""{{ fromyaml('[1, 2]') }}""") == "[1, 2]"
1796+
assert (
1797+
context.render("{% set my_yaml %}\n- good\n- bad\n{% endset %}{{ fromyaml(my_yaml) }}")
1798+
== "['good', 'bad']"
1799+
)
1800+
assert context.render("""{{ fromyaml('42') }}""") == "42"
17951801

17961802

17971803
@pytest.mark.xdist_group("dbt_manifest")

0 commit comments

Comments
 (0)