Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to silence events via WarnErrorOptions #112

Merged
merged 7 commits into from
Apr 23, 2024

Conversation

QMalcolm
Copy link
Contributor

resolves #111

Description

We want to be able to silence events via warn_or_error. This enables that.

Checklist

@QMalcolm QMalcolm requested a review from a team as a code owner April 20, 2024 06:22
@@ -36,6 +36,7 @@ class IncludeExclude(dbtClassMixin):

include: Union[str, List[str]]
exclude: List[str] = field(default_factory=list)
silence: List[str] = field(default_factory=list)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe a more appropriate place for this attribute would be on WarnErrorOptions itself, since IncludeExclude can be used by other interfaces as well that do not support silence. The silence functionality feels specific to the WarnErrorOptions mechanism itself -- which could override includes (and still probably leverage super().includes) to incorporate the business logic of handling self.silenced.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that. We'd also need to override the __post_init__ to validate the silence options. I'm not a huuuge fan of inheriting a class and then having to override every part of it though. Given these classes are still small it isn't a big deal, but much further I'd start strongly considering disconnecting or collapsing the classes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huuuge fan of inheriting a class and then having to override every part of it though.

Me neither, but given there is usage of IncludeExclude beyond the WarnErrorOptions class in dbt-core (e.g. in UnparsedVersion.columns), I'm nervous this will cause unintended changes to additional components beyond WarnErrorOptions.

Copy link
Contributor Author

@QMalcolm QMalcolm Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. You're absolutely right, the silence option really only makes sense from a logging standpoint, which is the privy of WarnErrorOptions, not IncludeExclude. I've gone and done the refactor in 61f7ff9.

Worth noting that the risk pre-refactor was low. This is because anything using IncludeExclude would not have changed behaviorly unless they began specifying silence

  • if nothing was silenced, everything operates normally
  • if instantiating with keyword args, and not specifying silence, then silence was empty
  • if instantiating with ordered args, and only specifying two args, then silence was empty

Technically since we modified `includes` in the previous commit, `warn_or_error`
started including `silenced` in it's logic then. However we make it explicit
in this commit, and begin testing it.
…es defined in tests

In the previous commit we defined a `Note` event class based on `WarnLevel`.
The logic in `get_all_subclasses` was getting test defined event classes, which
isn't what we want. Thus here we added logic to exclude these.
@QMalcolm QMalcolm force-pushed the qmalcolm--111-warn-error-silence-option branch from 0785b51 to 688556f Compare April 22, 2024 16:12
@codecov-commenter
Copy link

codecov-commenter commented Apr 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.26%. Comparing base (b76d0e6) to head (be987dc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #112      +/-   ##
==========================================
+ Coverage   55.79%   56.26%   +0.46%     
==========================================
  Files          50       50              
  Lines        3072     3082      +10     
==========================================
+ Hits         1714     1734      +20     
+ Misses       1358     1348      -10     
Flag Coverage Δ
unit 56.26% <100.00%> (+0.46%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@QMalcolm QMalcolm requested review from MichelleArk and emmyoop April 22, 2024 19:44
@@ -54,7 +54,7 @@ def __post_init__(self):
if isinstance(self.exclude, list):
self._validate_items(self.exclude)

def includes(self, item_name: str):
def includes(self, item_name: str) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emmyoop emmyoop added this pull request to the merge queue Apr 23, 2024
Merged via the queue into main with commit 7ee58a8 Apr 23, 2024
17 checks passed
@emmyoop emmyoop deleted the qmalcolm--111-warn-error-silence-option branch April 23, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support silence as part of WarnErrorOptions
4 participants