diff --git a/core/dbt/config/profile.py b/core/dbt/config/profile.py index 8fd1334c496..03af128dbde 100644 --- a/core/dbt/config/profile.py +++ b/core/dbt/config/profile.py @@ -44,10 +44,6 @@ {profiles_file}/profiles.yml """.format(profiles_file=PROFILES_DIR) -EMPTY_PROFILE_MESSAGE = """ -dbt cannot run because profiles.yml is empty for this dbt project. -""" - def read_profile(profiles_dir: str) -> Dict[str, Any]: path = os.path.join(profiles_dir, 'profiles.yml') @@ -58,7 +54,11 @@ def read_profile(profiles_dir: str) -> Dict[str, Any]: contents = load_file_contents(path, strip=False) yaml_content = load_yaml_text(contents) if not yaml_content: - raise DbtProfileError(EMPTY_PROFILE_MESSAGE) + raise DbtProfileError( + INVALID_PROFILE_MESSAGE.format( + error_string=f'The profiles.yml file at {path} is empty' + ) + ) return yaml_content except ValidationException as e: msg = INVALID_PROFILE_MESSAGE.format(error_string=e) @@ -287,7 +287,6 @@ def from_raw_profile_info( # user_cfg is not rendered. if user_cfg is None: user_cfg = raw_profile.get('config') - # TODO: should it be, and the values coerced to bool? target_name, profile_data = cls.render_profile( raw_profile, profile_name, target_override, renderer @@ -342,7 +341,15 @@ def from_raw_profiles( # First, we've already got our final decision on profile name, and we # don't render keys, so we can pluck that out raw_profile = raw_profiles[profile_name] - + if not raw_profile: + msg = ( + f'Profile {profile_name} in profiles.yml is empty' + ) + raise DbtProfileError( + INVALID_PROFILE_MESSAGE.format( + error_string=msg + ) + ) user_cfg = raw_profiles.get('config') return cls.from_raw_profile_info( @@ -380,7 +387,6 @@ def render_from_args( raw_profiles = read_profile(args.profiles_dir) profile_name = cls.pick_profile_name(getattr(args, 'profile', None), project_profile_name) - return cls.from_raw_profiles( raw_profiles=raw_profiles, profile_name=profile_name, diff --git a/test/unit/test_config.py b/test/unit/test_config.py index af5c4b66e02..5a5e73c34a9 100644 --- a/test/unit/test_config.py +++ b/test/unit/test_config.py @@ -157,7 +157,8 @@ def setUp(self): } }, 'target': 'other-postgres', - } + }, + 'empty_profile_data': {} } self.args = Args(profiles_dir=self.profiles_dir, cli_vars='{}', version_check=True, project_dir=self.project_dir) @@ -540,6 +541,17 @@ def test_empty_profile(self): self.from_args() self.assertIn('profiles.yml is empty', str(exc.exception)) + def test_profile_with_empty_profile_data(self): + renderer = empty_renderer() + with self.assertRaises(dbt.exceptions.DbtProfileError) as exc: + dbt.config.Profile.from_raw_profiles( + self.default_profile_data, 'empty_profile_data', renderer + ) + self.assertIn( + 'Profile empty_profile_data in profiles.yml is empty', + str(exc.exception) + ) + class TestProject(BaseConfigTest): def setUp(self):