Skip to content

Commit

Permalink
revert jinja version, implement tojson hack (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbanin authored Oct 24, 2017
1 parent cc9c185 commit c82d69f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
22 changes: 14 additions & 8 deletions dbt/context/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


{% macro make_hook_config(sql, inside_transaction) %}
{{ {"sql": sql, "transaction": inside_transaction} | tojson }}
{{ tojson({"sql": sql, "transaction": inside_transaction}) }}
{% endmacro %}


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit c82d69f

Please sign in to comment.