Skip to content

Commit adcf8bc

Browse files
authored
[CT-2551] Make state selection MECE (#7773)
* ct-2551: adds old and unmodified state selection methods * ct-2551: update check_unmodified_content to simplify * add unit and integration tests for unmodified and old * add changelog entry * ct-2551: reformatting of contingent adapter assignment list
1 parent 5d93780 commit adcf8bc

File tree

4 files changed

+331
-2
lines changed

4 files changed

+331
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: Features
2+
body: This change adds new selector methods to the state selector. Namely, state:unmodified
3+
and state:old.
4+
time: 2023-06-03T14:16:25.249884-05:00
5+
custom:
6+
Author: trouze
7+
Issue: "7564"

core/dbt/graph/selector_methods.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,11 @@ def check_modified_content(
542542
upstream_macro_change = self.check_macros_modified(new)
543543
return different_contents or upstream_macro_change
544544

545+
def check_unmodified_content(
546+
self, old: Optional[SelectorTarget], new: SelectorTarget, adapter_type: str
547+
) -> bool:
548+
return not self.check_modified_content(old, new, adapter_type)
549+
545550
def check_modified_macros(self, old, new: SelectorTarget) -> bool:
546551
return self.check_macros_modified(new)
547552

@@ -586,8 +591,10 @@ def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[Uniqu
586591
state_checks = {
587592
# it's new if there is no old version
588593
"new": lambda old, new: old is None,
594+
"old": lambda old, new: old is not None,
589595
# use methods defined above to compare properties of old + new
590596
"modified": self.check_modified_content,
597+
"unmodified": self.check_unmodified_content,
591598
"modified.body": self.check_modified_factory("same_body"),
592599
"modified.configs": self.check_modified_factory("same_config"),
593600
"modified.persisted_descriptions": self.check_modified_factory(
@@ -619,7 +626,11 @@ def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[Uniqu
619626
previous_node = manifest.metrics[node]
620627

621628
keyword_args = {}
622-
if checker.__name__ in ["same_contract", "check_modified_content"]:
629+
if checker.__name__ in [
630+
"same_contract",
631+
"check_modified_content",
632+
"check_unmodified_content",
633+
]:
623634
keyword_args["adapter_type"] = adapter_type # type: ignore
624635

625636
if checker(previous_node, real_node, **keyword_args): # type: ignore

0 commit comments

Comments
 (0)