diff --git a/dbt/context/common.py b/dbt/context/common.py index 063f8e44696..834e3cc3d19 100644 --- a/dbt/context/common.py +++ b/dbt/context/common.py @@ -233,13 +233,18 @@ def fn(string): return fn -def fromjson(node): - def fn(string, default=None): - try: - return json.loads(string) - except ValueError as e: - return default - return fn +def fromjson(string, default=None): + try: + return json.loads(string) + except ValueError as e: + return default + + +def tojson(value, default=None): + try: + return json.dumps(value) + except ValueError as e: + return default def _return(value): @@ -290,7 +295,8 @@ def generate(model, project, flat_graph, provider=None): "schema": model.get('schema', schema), "sql": model.get('injected_sql'), "sql_now": adapter.date_function(), - "fromjson": fromjson(model), + "fromjson": fromjson, + "tojson": tojson, "target": target, "this": dbt.utils.Relation(profile, adapter, model, use_temp=True) }) diff --git a/dbt/include/global_project/macros/materializations/helpers.sql b/dbt/include/global_project/macros/materializations/helpers.sql index 1171be00f69..f6e0563dd1b 100644 --- a/dbt/include/global_project/macros/materializations/helpers.sql +++ b/dbt/include/global_project/macros/materializations/helpers.sql @@ -22,7 +22,7 @@ {% macro make_hook_config(sql, inside_transaction) %} - {{ {"sql": sql, "transaction": inside_transaction} | tojson }} + {{ tojson({"sql": sql, "transaction": inside_transaction}) }} {% endmacro %} diff --git a/requirements.txt b/requirements.txt index 7960f2497be..262b002e96c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ argparse>=1.2.1 -Jinja2>=2.9 +Jinja2>=2.8 PyYAML>=3.11 psycopg2==2.7.1 sqlparse==0.2.3 diff --git a/setup.py b/setup.py index cca8e9458ca..336d01dbfd9 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ 'scripts/dbt', ], install_requires=[ - 'Jinja2>=2.9', + 'Jinja2>=2.8', 'PyYAML>=3.11', 'psycopg2==2.7.1', 'sqlparse==0.2.3',