dbt-labs / dbt-labs/dbt

[CT-2260] [Feature] Explainable state modified

Open
#7,109 2 comments 1 reaction 0 assignees View on GitHub
engine:v1 help_wanted node selection state state: modified type:feature
Dominant language
Rust
Stars
13.8k
Forks
2.6k
Avg merge
21h 31m
Merged PRs (30d)
56

Description

### Is this your first time submitting a feature request?

- [X] I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)
- [X] I have searched the existing issues, and I could not find an existing issue for this feature
- [X] I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

### Describe the feature

**Problem:**
I want to be able to explain a state:modified selection with fine grained diffs. I can code up a lot of ways to solve this but let me riff on what I think would be ideal.

**Solution:**
There are methods returning primitive types that should ideally be wrapper types that duck-type the effect of the primitive. Specifically, the methods I am calling out are planted all over the sort-of core dataclasses, and they return bools when, in an ideal world, they should return a specific class which implements `__bool__` but is, by effect of not being a binary primitive, significantly more extensible. We can do this whilst maintaining the contract with dependents of the method.

All of the `same_*` methods from `same_body` to `same_database_representation`
These should pass around a `Comparator` which has a baked in method called output diff which leverages `difflib` to generate a log-able diff of the node. This means `Comparator`'s will carry references to old and new, so that it is available as needed. And lastly, the diff is opt-in based on where we decide to plant the method calls. I can see the `-vv` verbosity level being the impetus to output the diff.

### Describe alternatives you've considered

So long as the `same_*` methods are restricted to `bool`s, there is no alternative.

### Who will this benefit?

Anyone troubleshooting why a model is running when they don't think or know if it was modified by providing a highly detailed `unified_diff`.

### Are you interested in contributing this feature?

Yes

### Anything else?

Slack Thread: https://getdbt.slack.com/archives/C50NEBJGG/p1675216311733109

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.