Skip to content

Commit

Permalink
fix #7407: print model version in dbt show if specified
Browse files Browse the repository at this point in the history
  • Loading branch information
aranke committed May 8, 2023
1 parent 810ef7f commit 88155e0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/dbt/task/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ def task_end_messages(self, results):
else:
table.print_table(output=output, max_rows=None)

node_name = result.node.name

if result.node.version:
node_name += f".v{result.node.version}"

fire_event(
ShowNode(
node_name=result.node.name,
node_name=node_name,
preview=output.getvalue(),
is_inline=is_inline,
output_format=self.args.output,
Expand Down
29 changes: 29 additions & 0 deletions tests/functional/show/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,35 @@
from {{ ref('sample_model') }}
"""

schema_yml = """
models:
- name: sample_model
latest_version: 1
# declare the versions, and fully specify them
versions:
- v: 2
config:
materialized: table
columns:
- name: sample_num
data_type: int
- name: sample_bool
data_type: bool
- name: answer
data_type: int
- v: 1
config:
materialized: table
contract: {enforced: true}
columns:
- name: sample_num
data_type: int
- name: sample_bool
data_type: bool
"""

models__ephemeral_model = """
{{ config(materialized = 'ephemeral') }}
select
Expand Down
27 changes: 27 additions & 0 deletions tests/functional/show/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
models__sample_model,
models__second_model,
models__ephemeral_model,
schema_yml,
)


Expand Down Expand Up @@ -85,3 +86,29 @@ def test_second_ephemeral_model(self, project):
["show", "--inline", models__second_ephemeral_model]
)
assert "col_hundo" in log_output


class TestShowModelVersions:
@pytest.fixture(scope="class")
def models(self):
return {
"schema.yml": schema_yml,
"sample_model.sql": models__sample_model,
"sample_model_v2.sql": models__second_model,
}

@pytest.fixture(scope="class")
def seeds(self):
return {"sample_seed.csv": seeds__sample_seed}

def test_version_unspecified(self, project):
run_dbt(["build"])
(results, log_output) = run_dbt_and_capture(["show", "--select", "sample_model"])
assert "Previewing node 'sample_model.v1'" in log_output
assert "Previewing node 'sample_model.v2'" in log_output

def test_none(self, project):
run_dbt(["build"])
(results, log_output) = run_dbt_and_capture(["show", "--select", "sample_model.v2"])
assert "Previewing node 'sample_model.v1'" not in log_output
assert "Previewing node 'sample_model.v2'" in log_output

0 comments on commit 88155e0

Please sign in to comment.