Skip to content

Commit

Permalink
Merge branch 'main' into add_jinja_is_list_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Oct 1, 2024
2 parents 8221314 + 60ffb06 commit 34b3efa
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20240920-165607.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: Restrict behavior change warning to firing once per run to avoid noisy warnings
in logs
time: 2024-09-20T16:56:07.951544-04:00
custom:
Author: mikealfare
Issue: "197"
2 changes: 1 addition & 1 deletion dbt_common/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.9.0"
version = "1.10.0"
5 changes: 4 additions & 1 deletion dbt_common/behavior_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class BehaviorFlagRendered:
user_overrides: a set of user settings, one of which may be an override on this behavior flag
"""

fired: bool = False

def __init__(self, flag: BehaviorFlag, user_overrides: Dict[str, Any]) -> None:
self._validate(flag)

Expand All @@ -72,8 +74,9 @@ def _validate(flag: BehaviorFlag) -> None:

@property
def setting(self) -> bool:
if self._setting is False:
if self._setting is False and not self.fired:
fire_event(self._behavior_change_event)
self.fired = True
return self._setting

@setting.setter
Expand Down
2 changes: 1 addition & 1 deletion dbt_common/exceptions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def process_stack(self) -> List[str]:
lines = []

if hasattr(self.node, "build_path") and self.node.build_path:
lines.append(f"compiled Code at {self.node.build_path}")
lines.append(f"compiled code at {self.node.build_path}")

return lines + DbtRuntimeError.process_stack(self)

Expand Down
32 changes: 32 additions & 0 deletions tests/unit/test_behavior_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,35 @@ def test_behavior_flags_no_behavior_change_event_on_no_warn(event_catcher: Event
def test_behavior_flag_requires_description_or_docs_url(event_catcher: EventCatcher) -> None:
with pytest.raises(DbtInternalError):
Behavior([{"name": "flag_false", "default": False}], {})


def test_behavior_flags_fire_once_per_flag(event_catcher: EventCatcher) -> None:
behavior = Behavior(
[
{"name": "flag_1", "default": False, "description": "This is flag 1."},
{"name": "flag_2", "default": False, "description": "This is flag 2."},
],
{},
)

assert len(event_catcher.caught_events) == 0

# trigger the evaluation for flag_1, an event should fire
if behavior.flag_1:
pass
assert len(event_catcher.caught_events) == 1

# trigger the evaluation for flag_1 again, no event should fire
if behavior.flag_1:
pass
assert len(event_catcher.caught_events) == 1

# trigger the evaluation for flag_2, an event should fire
if behavior.flag_2:
pass
assert len(event_catcher.caught_events) == 2

# trigger the evaluation for flag_1 again, no event should fire
if behavior.flag_1:
pass
assert len(event_catcher.caught_events) == 2

0 comments on commit 34b3efa

Please sign in to comment.