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

CT 1894 log partial parsing var changes and sort cli vars before hashing #6713

Merged
merged 4 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230124-141943.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Sort cli vars before hashing for partial parsing
time: 2023-01-24T14:19:43.333628-05:00
custom:
Author: gshank
Issue: "6710"
19 changes: 18 additions & 1 deletion core/dbt/events/proto_types.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion core/dbt/events/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,21 @@ message UnableToPartialParseMsg {
UnableToPartialParse data = 2;
}

// Skipped I025, I026, I027
// I025
message StateCheckVarsHash {
string checksum = 1;
string vars = 2;
string profile = 3;
string target = 4;
string version = 5;
}

message StateCheckVarsHashMsg {
EventInfo info = 1;
StateCheckVarsHash data = 2;
}

// Skipped I026, I027


// I028
Expand Down
9 changes: 9 additions & 0 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,15 @@ def message(self) -> str:
return f"Unable to do partial parsing because {self.reason}"


@dataclass
class StateCheckVarsHash(DebugLevel, pt.StateCheckVarsHash):
def code(self):
return "I025"

def message(self) -> str:
return "checksum: {self.checksum}, vars: {self.vars}, profile: {self.profile}, target: {self.target}, version: {self.version}"
gshank marked this conversation as resolved.
Show resolved Hide resolved


# Skipped I025, I026, I026, I027


Expand Down
23 changes: 22 additions & 1 deletion core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from itertools import chain
import time
from dbt.events.base_types import EventLevel
import pprint

import dbt.exceptions
import dbt.tracking
Expand All @@ -29,6 +30,8 @@
ParsedFileLoadFailed,
InvalidDisabledTargetInTestNode,
NodeNotFoundOrDisabled,
StateCheckVarsHash,
Note,
)
from dbt.logger import DbtProcessState
from dbt.node_types import NodeType
Expand Down Expand Up @@ -569,6 +572,12 @@ def is_partial_parsable(self, manifest: Manifest) -> Tuple[bool, Optional[str]]:
reason="config vars, config profile, or config target have changed"
)
)
fire_event(
Note(
msg=f"previous checksum: {self.manifest.state_check.vars_hash.checksum}, current checksum: {manifest.state_check.vars_hash.checksum}"
),
level=EventLevel.DEBUG,
)
valid = False
reparse_reason = ReparseReason.vars_changed
if self.manifest.state_check.profile_hash != manifest.state_check.profile_hash:
Expand Down Expand Up @@ -702,16 +711,28 @@ def build_manifest_state_check(self):
# arg vars, but since any changes to that file will cause state_check
# to not pass, it doesn't matter. If we move to more granular checking
# of env_vars, that would need to change.
# We are using the parsed cli_vars instead of config.args.vars, in order
# to sort them and avoid reparsing because of ordering issues.
stringified_cli_vars = pprint.pformat(config.cli_vars)
vars_hash = FileHash.from_contents(
"\x00".join(
[
getattr(config.args, "vars", "{}") or "{}",
stringified_cli_vars,
dbeatty10 marked this conversation as resolved.
Show resolved Hide resolved
getattr(config.args, "profile", "") or "",
getattr(config.args, "target", "") or "",
__version__,
]
)
)
fire_event(
StateCheckVarsHash(
checksum=vars_hash.checksum,
vars=stringified_cli_vars,
profile=config.args.profile,
target=config.args.target,
version=__version__,
)
)

# Create a FileHash of the env_vars in the project
key_list = list(config.project_env_vars.keys())
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def test_event_codes(self):
PartialParsingError(exc_info={}),
PartialParsingSkipParsing(),
UnableToPartialParse(reason="something went wrong"),
StateCheckVarsHash(vars="testing", target="testing", profile="testing"),
PartialParsingNotEnabled(),
ParsedFileLoadFailed(path="", exc="", exc_info=""),
StaticParserCausedJinjaRendering(path=""),
Expand Down