Skip to content

Commit e930b7b

Browse files
Marthe Van Den Hendetomasfarias
authored andcommitted
include PR feedback
1 parent cfde08b commit e930b7b

6 files changed

Lines changed: 56 additions & 28 deletions

File tree

airflow_dbt_python/utils/configs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,11 @@ def __post_init__(self):
619619
"""Call superclass __post_init__."""
620620
super().__post_init__()
621621
if isinstance(self.full_refresh, str):
622+
if self.full_refresh.lower() not in ("true", "false"):
623+
raise ValueError(
624+
f"Invalid value for full_refresh: '{self.full_refresh}'. "
625+
"Expected 'true' or 'false'."
626+
)
622627
self.full_refresh = self.full_refresh.lower() == "true"
623628

624629

tests/operators/test_dbt_build.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,12 @@ def test_full_refresh_in_template_fields():
242242

243243

244244
def test_full_refresh_templated():
245-
"""Test that full_refresh can be templated with Jinja."""
245+
"""Test that full_refresh can be templated with Jinja.
246+
247+
Airflow renders template fields as strings, so the operator receives a
248+
string after rendering. The string-to-bool coercion happens in
249+
TableMutabilityConfig and is tested in test_configs.py.
250+
"""
246251
import pendulum
247252
from airflow.models.dag import DAG
248253

tests/operators/test_dbt_compile.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,12 @@ def test_full_refresh_in_template_fields():
214214

215215

216216
def test_full_refresh_templated():
217-
"""Test that full_refresh can be templated with Jinja."""
217+
"""Test that full_refresh can be templated with Jinja.
218+
219+
Airflow renders template fields as strings, so the operator receives a
220+
string after rendering. The string-to-bool coercion happens in
221+
TableMutabilityConfig and is tested in test_configs.py.
222+
"""
218223
import pendulum
219224
from airflow.models.dag import DAG
220225

tests/operators/test_dbt_run.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,12 @@ def test_full_refresh_in_template_fields():
436436

437437

438438
def test_full_refresh_templated():
439-
"""Test that full_refresh can be templated with Jinja."""
439+
"""Test that full_refresh can be templated with Jinja.
440+
441+
Airflow renders template fields as strings, so the operator receives a
442+
string after rendering. The string-to-bool coercion happens in
443+
TableMutabilityConfig and is tested in test_configs.py.
444+
"""
440445
from airflow.models.dag import DAG
441446

442447
dag = DAG(dag_id="test_dag", start_date=pendulum.datetime(2025, 1, 1))

tests/operators/test_dbt_seed.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,12 @@ def test_full_refresh_in_template_fields():
335335

336336

337337
def test_full_refresh_templated():
338-
"""Test that full_refresh can be templated with Jinja."""
338+
"""Test that full_refresh can be templated with Jinja.
339+
340+
Airflow renders template fields as strings, so the operator receives a
341+
string after rendering. The string-to-bool coercion happens in
342+
TableMutabilityConfig and is tested in test_configs.py.
343+
"""
339344
import pendulum
340345
from airflow.models.dag import DAG
341346

tests/utils/test_configs.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -508,34 +508,37 @@ def test_base_config_does_not_override_when_value_in_environment(
508508
assert config.require_generic_test_arguments_property is None
509509

510510

511-
def test_table_mutability_config_full_refresh_string_coercion(
512-
profiles_file, dbt_project_file
511+
@pytest.mark.parametrize(
512+
"input_value,expected",
513+
[
514+
("True", True),
515+
("true", True),
516+
("False", False),
517+
("false", False),
518+
(True, True),
519+
(False, False),
520+
(None, None),
521+
],
522+
)
523+
def test_table_mutability_config_full_refresh_coercion(
524+
profiles_file, dbt_project_file, input_value, expected
513525
):
514-
"""Test that full_refresh string values are coerced to booleans."""
526+
"""Test that full_refresh values are coerced to booleans."""
515527
config = RunTaskConfig(
516528
profiles_dir=profiles_file.parent,
517529
project_dir=dbt_project_file.parent,
518-
full_refresh="True",
530+
full_refresh=input_value,
519531
)
520-
assert config.full_refresh is True
532+
assert config.full_refresh is expected
521533

522-
config = RunTaskConfig(
523-
profiles_dir=profiles_file.parent,
524-
project_dir=dbt_project_file.parent,
525-
full_refresh="False",
526-
)
527-
assert config.full_refresh is False
528534

529-
config = RunTaskConfig(
530-
profiles_dir=profiles_file.parent,
531-
project_dir=dbt_project_file.parent,
532-
full_refresh=None,
533-
)
534-
assert config.full_refresh is None
535-
536-
config = RunTaskConfig(
537-
profiles_dir=profiles_file.parent,
538-
project_dir=dbt_project_file.parent,
539-
full_refresh=True,
540-
)
541-
assert config.full_refresh is True
535+
def test_table_mutability_config_full_refresh_invalid_string(
536+
profiles_file, dbt_project_file
537+
):
538+
"""Test that invalid full_refresh strings raise a ValueError."""
539+
with pytest.raises(ValueError, match="Invalid value for full_refresh"):
540+
RunTaskConfig(
541+
profiles_dir=profiles_file.parent,
542+
project_dir=dbt_project_file.parent,
543+
full_refresh="treu",
544+
)

0 commit comments

Comments
 (0)