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

Fix project dir argument when running debug (#1733) #1989

Merged
Merged
Show file tree
Hide file tree
Changes from all 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: 4 additions & 2 deletions core/dbt/task/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '{}')
)
Expand Down Expand Up @@ -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')
Expand Down
24 changes: 24 additions & 0 deletions test/integration/049_dbt_debug_test/test_debug.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from test.integration.base import DBTIntegrationTest, use_profile
import os
import re
import yaml

import pytest

Expand Down Expand Up @@ -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)