diff --git a/core/dbt/task/debug.py b/core/dbt/task/debug.py index 748de5a38be..d40bf9f1533 100644 --- a/core/dbt/task/debug.py +++ b/core/dbt/task/debug.py @@ -69,7 +69,8 @@ def __init__(self, args, config): self.profiles_dir = getattr(self.args, 'profiles_dir', dbt.config.PROFILES_DIR) self.profile_path = os.path.join(self.profiles_dir, 'profiles.yml') - self.project_path = os.path.join(os.getcwd(), 'dbt_project.yml') + self.project_dir = args.project_dir or os.getcwd() + self.project_path = os.path.join(self.project_dir, 'dbt_project.yml') self.cli_vars = dbt.utils.parse_cli_vars( getattr(self.args, 'vars', '{}') ) @@ -125,7 +126,8 @@ def _load_project(self): return red('ERROR not found') try: - self.project = Project.from_current_directory(self.cli_vars) + self.project = Project.from_project_root(self.project_dir, + self.cli_vars) except dbt.exceptions.DbtConfigError as exc: self.project_fail_details = str(exc) return red('ERROR invalid') diff --git a/test/integration/049_dbt_debug_test/test_debug.py b/test/integration/049_dbt_debug_test/test_debug.py index bdd4639e5bc..c76b2e0f544 100644 --- a/test/integration/049_dbt_debug_test/test_debug.py +++ b/test/integration/049_dbt_debug_test/test_debug.py @@ -1,6 +1,7 @@ from test.integration.base import DBTIntegrationTest, use_profile import os import re +import yaml import pytest @@ -103,3 +104,26 @@ def test_postgres_badproject(self): self.assertIn('ERROR invalid', line) elif line.strip().startswith('profiles.yml file'): self.assertNotIn('ERROR invalid', line) + + @use_profile('postgres') + def test_postgres_not_found_project_dir(self): + self.run_dbt(['debug', '--project-dir', 'nopass']) + splitout = self.capsys.readouterr().out.split('\n') + for line in splitout: + if line.strip().startswith('dbt_project.yml file'): + self.assertIn('ERROR not found', line) + + @use_profile('postgres') + def test_postgres_invalid_project_outside_current_dir(self): + # create a dbt_project.yml + project_config = { + 'invalid-key': 'not a valid key in this project' + } + os.makedirs('custom', exist_ok=True) + with open("custom/dbt_project.yml", 'w') as f: + yaml.safe_dump(project_config, f, default_flow_style=True) + self.run_dbt(['debug', '--project-dir', 'custom']) + splitout = self.capsys.readouterr().out.split('\n') + for line in splitout: + if line.strip().startswith('dbt_project.yml file'): + self.assertIn('ERROR invalid', line)