Skip to content

Commit

Permalink
Cleanup redundant code and help logic along.
Browse files Browse the repository at this point in the history
  • Loading branch information
VersusFacit committed Jun 6, 2023
1 parent d925dc4 commit 9a37ba5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .changes/unreleased/Features-20230604-025956.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ body: Revamp debug, add --connection flag. Prepare for future refactors/interfac
time: 2023-06-04T02:59:56.28283-07:00
custom:
Author: versusfacit
Issue: 7104 7774
Issue: 7104
33 changes: 24 additions & 9 deletions core/dbt/task/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class RunStatus(Enum):
SKIP = 3


DEBUG_RUN_STATUS: Dict[str, bool] = {
"pass": True,
"fail": False,
}


class DebugTask(BaseTask):
def __init__(self, args, config):
super().__init__(args, config)
Expand Down Expand Up @@ -109,10 +115,10 @@ def path_info(self):
open_cmd = dbt.clients.system.open_dir_cmd()
fire_event(OpenCommand(open_cmd=open_cmd, profiles_dir=self.profiles_dir))

def run(self):
def run(self) -> bool:
if self.args.config_dir:
self.path_info()
return True
return DEBUG_RUN_STATUS["pass"]

version = get_installed_version().to_version_string(skip_matcher=True)
fire_event(DebugCmdOut(msg="dbt version: {}".format(version)))
Expand All @@ -126,7 +132,13 @@ def run(self):
fire_event(DebugCmdOut(msg="Using profiles.yml file at {}".format(self.profile_path)))
fire_event(DebugCmdOut(msg="Using dbt_project.yml file at {}".format(self.project_path)))
if load_profile_status.run_status == RunStatus.PASS:
adapter_type = self.profile.credentials.type
if self.profile is not None:
adapter_type = self.profile.credentials.type
else:
raise dbt.exceptions.DbtInternalError(
"Profile should not be None if loading profile completed"
)

adapter_version = self._read_adapter_version(
f"dbt.adapters.{adapter_type}.__version__"
)
Expand All @@ -148,16 +160,19 @@ def run(self):

# Log messages from any fails
all_statuses = [load_profile_status, load_project_status, *dependencies_statuses]
failure_count = sum(1 for status in all_statuses if status.run_status == RunStatus.FAIL)
all_failing_statuses = list(
filter(lambda status: status.run_status == RunStatus.FAIL, all_statuses)
)

failure_count = len(all_failing_statuses)
if failure_count > 0:
fire_event(DebugCmdResult(msg=red(f"{(pluralize(failure_count, 'check'))} failed:")))
for status in all_failing_statuses:
fire_event(DebugCmdResult(msg=f"{status.summary_message}\n"))
return DEBUG_RUN_STATUS["fail"]
else:
fire_event(DebugCmdResult(msg=green("All checks passed!")))

for status in filter(lambda status: status.run_status == RunStatus.FAIL, all_statuses):
fire_event(DebugCmdResult(msg=f"{status.summary_message}\n"))

return failure_count == 0
return DEBUG_RUN_STATUS["pass"]

# ==============================
# Override for elsewhere in core
Expand Down

0 comments on commit 9a37ba5

Please sign in to comment.