diff --git a/core/dbt/task/show.py b/core/dbt/task/show.py index 58e0948bcfb..e389428d2d0 100644 --- a/core/dbt/task/show.py +++ b/core/dbt/task/show.py @@ -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, diff --git a/tests/functional/show/fixtures.py b/tests/functional/show/fixtures.py index 6fa89b32893..48248195b72 100644 --- a/tests/functional/show/fixtures.py +++ b/tests/functional/show/fixtures.py @@ -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 diff --git a/tests/functional/show/test_show.py b/tests/functional/show/test_show.py index c5684197ec5..aa5dbb6025c 100644 --- a/tests/functional/show/test_show.py +++ b/tests/functional/show/test_show.py @@ -8,6 +8,7 @@ models__sample_model, models__second_model, models__ephemeral_model, + schema_yml, ) @@ -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