Skip to content

Commit

Permalink
Allow users to set the flag full-refresh when running models
Browse files Browse the repository at this point in the history
  • Loading branch information
tatiana committed Sep 12, 2023
1 parent d09abc5 commit fe36958
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion cosmos/operators/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,21 @@ class DbtRunLocalOperator(DbtLocalBaseOperator):
ui_color = "#7352BA"
ui_fgcolor = "#F4F2FC"

def __init__(self, **kwargs: Any) -> None:
def __init__(self, full_refresh: bool = False, **kwargs: Any) -> None:
self.full_refresh = full_refresh
super().__init__(**kwargs)
self.base_cmd = ["run"]

def add_cmd_flags(self) -> list[str]:
flags = []
if self.full_refresh is True:
flags.append("--full-refresh")
return flags

def execute(self, context: Context) -> None:
cmd_flags = self.add_cmd_flags()
self.build_and_run_cmd(context=context, cmd_flags=cmd_flags)


class DbtTestLocalOperator(DbtLocalBaseOperator):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/operators/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def test_store_compiled_sql() -> None:
"operator_class,kwargs,expected_call_kwargs",
[
(DbtSeedLocalOperator, {"full_refresh": True}, {"context": {}, "cmd_flags": ["--full-refresh"]}),
(DbtRunLocalOperator, {"full_refresh": True}, {"context": {}, "cmd_flags": ["--full-refresh"]}),
(
DbtRunOperationLocalOperator,
{"args": {"days": 7, "dry_run": True}, "macro_name": "bla"},
Expand All @@ -264,7 +265,6 @@ def test_operator_execute_with_flags(mock_build_and_run_cmd, operator_class, kwa
(
DbtLSLocalOperator,
DbtSnapshotLocalOperator,
DbtRunLocalOperator,
DbtTestLocalOperator,
DbtDocsLocalOperator,
DbtDocsS3LocalOperator,
Expand Down

0 comments on commit fe36958

Please sign in to comment.