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

[Backport 1.5.latest] fix #7407: print model version in dbt show if specified #7557

Merged
merged 1 commit into from
May 10, 2023
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
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