Skip to content

Commit

Permalink
Typo and fix linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
kadero committed Oct 2, 2021
1 parent 51513d2 commit d61225a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions core/dbt/contracts/graph/unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def exceeded(self, actual_age: float) -> bool:
def __bool__(self):
return self.count is not None and self.period is not None


@dataclass
class FreshnessThreshold(dbtClassMixin, Mergeable):
warn_after: Optional[Time] = field(default_factory=Time)
Expand Down
18 changes: 11 additions & 7 deletions core/dbt/parser/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,28 +344,32 @@ def get_unused_msg(
msg.append('')
return '\n'.join(msg)

def merge_time(base: Optional[Time], update: Optional[Time]) -> Optional[Time]:

def merge_freshness_time_thresholds(
base: Optional[Time], update: Optional[Time]
) -> Optional[Time]:
if base is None and update is None:
return None
elif base is None and update is not None:
return update
elif base is not None and update is None:
return base
else:
# base and update not none
# base and update are not none
return base.merged(update)


def merge_freshness(
base: Optional[FreshnessThreshold], update: Optional[FreshnessThreshold]
) -> Optional[FreshnessThreshold]:
if base is not None and update is not None:
merged_freshness = base.merged(update)
# merge one level deeper error and warn after threshold
merged_error_after = merge_time(base.error_after, update.error_after)
merged_warn_after = merge_time(base.warn_after, update.warn_after)
# merge one level deeper the error_after and warn_after thresholds
merged_error_after = merge_freshness_time_thresholds(base.error_after, update.error_after)
merged_warn_after = merge_freshness_time_thresholds(base.warn_after, update.warn_after)

merged_freshness.error_after = merged_error_after
merged_freshness.warn_after = merged_warn_after
merged_freshness.warn_after = merged_warn_after
return merged_freshness
elif base is None and update is not None:
return update
Expand Down

0 comments on commit d61225a

Please sign in to comment.