Skip to content

Commit 52e3be3

Browse files
Fixes dbt retry does not respect --threads (#10591) (#11447)
Co-authored-by: Apoorv Mehrotra <[email protected]>
1 parent 9ed089a commit 52e3be3

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Fixes
2+
body: dbt retry does not respect --threads
3+
time: 2024-08-22T12:21:32.358066+05:30
4+
custom:
5+
Author: donjin-master
6+
Issue: "10584"

core/dbt/task/retry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"warn_error",
4343
}
4444

45-
ALLOW_CLI_OVERRIDE_FLAGS = {"vars"}
45+
ALLOW_CLI_OVERRIDE_FLAGS = {"vars", "threads"}
4646

4747
TASK_DICT = {
4848
"build": BuildTask,

tests/functional/retry/fixtures.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
models__sample_model = """select 1 as id, baz as foo"""
22
models__second_model = """select 1 as id, 2 as bar"""
3+
models__thread_model = """select idx as id"""
34

45
models__union_model = """
56
select foo + bar as sum3 from {{ ref('sample_model') }}
@@ -58,3 +59,13 @@
5859
data_tests:
5960
- not_null
6061
"""
62+
63+
schema_test_thread_yml = """
64+
models:
65+
- name: thread_model
66+
columns:
67+
- name: id
68+
data_tests:
69+
- not_null
70+
71+
"""
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import pytest
2+
3+
from dbt.contracts.results import RunStatus, TestStatus
4+
from dbt.tests.util import run_dbt, write_file
5+
from tests.functional.retry.fixtures import models__thread_model, schema_test_thread_yml
6+
7+
8+
class TestCustomThreadRetry:
9+
@pytest.fixture(scope="class")
10+
def models(self):
11+
return {
12+
"thread_model.sql": models__thread_model,
13+
"schema.yml": schema_test_thread_yml,
14+
}
15+
16+
def test_thread_target(self, project):
17+
# Passing Threads to check
18+
results = run_dbt(
19+
["build", "--select", "thread_model", "--threads", "3"], expect_pass=False
20+
)
21+
expected_statuses = {
22+
"thread_model": RunStatus.Error,
23+
"not_null_thread_model_id": TestStatus.Skipped,
24+
}
25+
assert {n.node.name: n.status for n in results.results} == expected_statuses
26+
27+
# Retry Running the Dbt with simple Retry
28+
results = run_dbt(["retry", "--threads", "2"], expect_pass=False)
29+
expected_statuses = {
30+
"thread_model": RunStatus.Error,
31+
"not_null_thread_model_id": TestStatus.Skipped,
32+
}
33+
assert {n.node.name: n.status for n in results.results} == expected_statuses
34+
assert results.args["threads"] == 2
35+
36+
# running with retry withour threads
37+
results = run_dbt(["retry"], expect_pass=False)
38+
expected_statuses = {
39+
"thread_model": RunStatus.Error,
40+
"not_null_thread_model_id": TestStatus.Skipped,
41+
}
42+
assert {n.node.name: n.status for n in results.results} == expected_statuses
43+
assert results.args["threads"] == 2
44+
45+
# Retry with fixing the model and running with --threads 1
46+
fixed_sql = "select 1 as id"
47+
write_file(fixed_sql, "models", "thread_model.sql")
48+
49+
results = run_dbt(["retry", "--threads", "1"])
50+
expected_statuses = {
51+
"thread_model": RunStatus.Success,
52+
"not_null_thread_model_id": TestStatus.Pass,
53+
}
54+
55+
assert {n.node.name: n.status for n in results.results} == expected_statuses
56+
assert results.args["threads"] == 1

0 commit comments

Comments
 (0)