Skip to content

Commit

Permalink
Merge pull request #1 from Hosuke/main
Browse files Browse the repository at this point in the history
Check if ref name is a jinja var before add to models
  • Loading branch information
dot2dotseurat authored Nov 17, 2022
2 parents dfb6227 + e191506 commit 17ff845
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pre_commit_dbt/check_script_ref_and_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def check_refs_sources(
for src_ref in src_refs:
src_ref_value = src_ref[1].replace("'", "").replace('"', "").strip()
if src_ref[0] == "ref":
models.add(src_ref_value)
is_jinja_var = re.search(r"\{\%.*" + src_ref_value + ".*\%\}", full_script)
if not is_jinja_var:
models.add(src_ref_value)
if src_ref[0] == "source":
src_split = src_ref_value.split(",")
source_name = src_split[0].strip()
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/test_script_ref_and_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,43 @@
1,
False,
),
(
"""
{% set dao_proposals_models = [
'uniswap_v3_ethereum_proposals'
] %}
SELECT *
FROM (
{% for dao_model in dao_proposals_models %}
SELECT
blockchain,
project,
version,
created_at,
tx_hash,
dao_name,
dao_address,
proposer,
proposal_id,
votes_for,
votes_against,
votes_abstain,
votes_total,
number_of_voters,
participation,
status,
description
FROM {{ ref(dao_model) }}
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
)
""",
0,
True,
),
)


Expand Down

0 comments on commit 17ff845

Please sign in to comment.