Skip to content

Commit 31fd52d

Browse files
committed
fix: Change type of BaseConfig.state to Path
1 parent 415eb81 commit 31fd52d

File tree

7 files changed

+17
-8
lines changed

7 files changed

+17
-8
lines changed

airflow_dbt_python/hooks/dbt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,16 @@ class BaseConfig:
108108
log_cache_events: Optional[bool] = None
109109
defer: Optional[bool] = None
110110
no_defer: Optional[bool] = None
111-
state: Optional[str] = None
111+
state: Optional[Path] = None
112112
threads: Optional[int] = None
113113
compiled_target: Optional[Union["os.PathLike[str]", str]] = None
114114

115115
def __post_init__(self):
116116
"""Support dictionary args by casting them to str after setting."""
117117
if isinstance(self.vars, dict):
118118
self.vars = json.dumps(self.vars)
119+
if isinstance(self.state, str):
120+
self.state = Path(self.state)
119121

120122
@property
121123
def dbt_task(self) -> BaseTask:

tests/operators/test_dbt_build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Unit test module for DbtBuildOperator."""
22
import json
3+
from pathlib import Path
34
from unittest.mock import patch
45

56
import pytest
@@ -62,7 +63,7 @@ def test_dbt_build_mocked_all_args():
6263
]
6364
assert config.exclude == ["/path/to/model/to/exclude.sql"]
6465
assert config.selector_name == ["a-selector"]
65-
assert config.state == "/path/to/state/"
66+
assert config.state == Path("/path/to/state/")
6667
assert config.data is True
6768
assert config.schema is True
6869
assert config.show is True

tests/operators/test_dbt_compile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Unit test module for DbtCompileOperator."""
2+
from pathlib import Path
3+
24
from dbt.contracts.results import RunStatus
35

46
from airflow_dbt_python.hooks.dbt import CompileTaskConfig
@@ -48,7 +50,7 @@ def test_dbt_compile_mocked_all_args():
4850
]
4951
assert config.exclude == ["/path/to/data/to/exclude.sql"]
5052
assert config.selector_name == ["a-selector"]
51-
assert config.state == "/path/to/state/"
53+
assert config.state == Path("/path/to/state/")
5254

5355

5456
def test_dbt_compile_non_existent_model(profiles_file, dbt_project_file, model_files):

tests/operators/test_dbt_run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Unit test module for DbtRunOperator."""
22
import json
3+
from pathlib import Path
34

45
import pytest
56
from dbt.contracts.results import RunStatus
@@ -54,7 +55,7 @@ def test_dbt_run_mocked_all_args():
5455
assert config.select == ["/path/to/model.sql", "+/another/model.sql+2"]
5556
assert config.exclude == ["/path/to/model/to/exclude.sql"]
5657
assert config.selector_name == ["a-selector"]
57-
assert config.state == "/path/to/state/"
58+
assert config.state == Path("/path/to/state/")
5859

5960

6061
def test_dbt_run_non_existent_model(profiles_file, dbt_project_file, model_files):

tests/operators/test_dbt_seed.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Unit test module for DbtSeedOperator."""
22
import json
3+
from pathlib import Path
34
from unittest.mock import patch
45

56
import pytest
@@ -55,7 +56,7 @@ def test_dbt_seed_mocked_all_args():
5556
assert config.show is True
5657
assert config.exclude == ["/path/to/data/to/exclude.csv"]
5758
assert config.selector_name == ["a-selector"]
58-
assert config.state == "/path/to/state/"
59+
assert config.state == Path("/path/to/state/")
5960

6061

6162
def test_dbt_seed_non_existent_file(profiles_file, dbt_project_file, seed_files):

tests/operators/test_dbt_snapshot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Unit test module for DbtSnapshotOperator."""
2-
from unittest.mock import patch
2+
from pathlib import Path
33

44
import pytest
55
from dbt.contracts.results import RunStatus
@@ -41,7 +41,7 @@ def test_dbt_snapshot_mocked_all_args():
4141
assert config.select == ["/path/to/models"]
4242
assert config.exclude == ["/path/to/data/to/exclude.sql"]
4343
assert config.selector_name == ["a-selector"]
44-
assert config.state == "/path/to/state/"
44+
assert config.state == Path("/path/to/state/")
4545

4646

4747
def test_dbt_snapshot(profiles_file, dbt_project_file, snapshot_files):

tests/operators/test_dbt_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Unit test module for DbtTestOperator."""
2+
from pathlib import Path
3+
24
import pytest
35
from dbt.contracts.results import TestStatus
46

@@ -55,7 +57,7 @@ def test_dbt_test_configuration_all_args():
5557
assert config.select == ["/path/to/models"]
5658
assert config.exclude == ["/path/to/data/to/exclude.sql"]
5759
assert config.selector_name == ["a-selector"]
58-
assert config.state == "/path/to/state/"
60+
assert config.state == Path("/path/to/state/")
5961
assert config.no_defer is True
6062

6163

0 commit comments

Comments
 (0)