Skip to content

Commit

Permalink
fix #7407: print model version in dbt show if specified (#7543) (#7557
Browse files Browse the repository at this point in the history
)

(cherry picked from commit 40aca4b)

Co-authored-by: Kshitij Aranke <kshitij.aranke@dbtlabs.com>
  • Loading branch information
github-actions[bot] and aranke authored May 10, 2023
1 parent cb9e4d5 commit c578e5b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230508-042707.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: print model version in dbt show if specified
time: 2023-05-08T04:27:07.9965-07:00
custom:
Author: aranke
Issue: "7407"
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 hasattr(result.node, "version") and 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 c578e5b

Please sign in to comment.