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

revert jinja version, use custom tojson function in hooks #572

Merged
merged 1 commit into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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