diff --git a/core/dbt/config/profile.py b/core/dbt/config/profile.py index 618aecd8054..8fd1334c496 100644 --- a/core/dbt/config/profile.py +++ b/core/dbt/config/profile.py @@ -44,6 +44,10 @@ {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') @@ -52,7 +56,10 @@ def read_profile(profiles_dir: str) -> Dict[str, Any]: if os.path.isfile(path): try: contents = load_file_contents(path, strip=False) - return load_yaml_text(contents) + yaml_content = load_yaml_text(contents) + if not yaml_content: + raise DbtProfileError(EMPTY_PROFILE_MESSAGE) + return yaml_content except ValidationException as e: msg = INVALID_PROFILE_MESSAGE.format(error_string=e) raise ValidationException(msg) from e diff --git a/test/unit/test_config.py b/test/unit/test_config.py index 19a6f6ee231..af5c4b66e02 100644 --- a/test/unit/test_config.py +++ b/test/unit/test_config.py @@ -211,6 +211,10 @@ def write_profile(self, profile_data=None): with open(self.profile_path('profiles.yml'), 'w') as fp: yaml.dump(profile_data, fp) + def write_empty_profile(self): + with open(self.profile_path('profiles.yml'), 'w') as fp: + yaml.dump('', fp) + class TestProfile(BaseConfigTest): def setUp(self): @@ -530,6 +534,12 @@ def test_no_profile(self): self.from_args(project_profile_name=None) self.assertIn('no profile was specified', str(exc.exception)) + def test_empty_profile(self): + self.write_empty_profile() + with self.assertRaises(dbt.exceptions.DbtProfileError) as exc: + self.from_args() + self.assertIn('profiles.yml is empty', str(exc.exception)) + class TestProject(BaseConfigTest): def setUp(self):