Skip to content

Commit 6b36b18

Browse files
emmyoopNathaniel May
authored andcommitted
config call sites (#4169)
* update config use structured logging * WIP * minor cleanup * fixed merge error * added in ShowException * added todo to remove defaults after dropping 3.6 * removed todo that is obsolete
1 parent d8868c5 commit 6b36b18

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-18
lines changed

core/dbt/config/profile.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
from dbt.exceptions import ValidationException
1616
from dbt.exceptions import RuntimeException
1717
from dbt.exceptions import validator_error_message
18-
from dbt.logger import GLOBAL_LOGGER as logger
18+
from dbt.events.types import MissingProfileTarget
19+
from dbt.events.functions import fire_event
1920
from dbt.utils import coerce_dict_str
2021

2122
from .renderer import ProfileRenderer
@@ -293,10 +294,7 @@ def render_profile(
293294
target_name = renderer.render_value(raw_profile['target'])
294295
else:
295296
target_name = 'default'
296-
logger.debug(
297-
"target not specified in profile '{}', using '{}'"
298-
.format(profile_name, target_name)
299-
)
297+
fire_event(MissingProfileTarget(profile_name=profile_name, target_name=target_name))
300298

301299
raw_profile_data = cls._get_profile_data(
302300
raw_profile, profile_name, target_name

core/dbt/config/runtime.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
from dbt.contracts.connection import AdapterRequiredConfig, Credentials
2020
from dbt.contracts.graph.manifest import ManifestMetadata
2121
from dbt.contracts.relation import ComponentName
22-
from dbt.logger import GLOBAL_LOGGER as logger
22+
from dbt.events.types import ProfileLoadError, ProfileNotFound
23+
from dbt.events.functions import fire_event
2324
from dbt.ui import warning_tag
2425

2526
from dbt.contracts.project import Configuration, UserConfig
@@ -544,13 +545,8 @@ def _get_rendered_profile(
544545
args, profile_renderer, profile_name
545546
)
546547
except (DbtProjectError, DbtProfileError) as exc:
547-
logger.debug(
548-
'Profile not loaded due to error: {}', exc, exc_info=True
549-
)
550-
logger.info(
551-
'No profile "{}" found, continuing with no target',
552-
profile_name
553-
)
548+
fire_event(ProfileLoadError(exc=exc))
549+
fire_event(ProfileNotFound(profile_name=profile_name))
554550
# return the poisoned form
555551
profile = UnsetProfile()
556552
# disable anonymous usage statistics

core/dbt/config/utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from typing import Dict, Any
22

33
from dbt.clients import yaml_helper
4+
from dbt.events.functions import fire_event
45
from dbt.exceptions import raise_compiler_error, ValidationException
5-
from dbt.logger import GLOBAL_LOGGER as logger
6+
from dbt.events.types import InvalidVarsYAML
67

78

89
def parse_cli_vars(var_string: str) -> Dict[str, Any]:
@@ -17,7 +18,5 @@ def parse_cli_vars(var_string: str) -> Dict[str, Any]:
1718
"The --vars argument must be a YAML dictionary, but was "
1819
"of type '{}'".format(type_name))
1920
except ValidationException:
20-
logger.error(
21-
"The YAML provided in the --vars argument is not valid.\n"
22-
)
21+
fire_event(InvalidVarsYAML())
2322
raise

core/dbt/events/types.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from abc import ABCMeta, abstractmethod
22
from dataclasses import dataclass
3-
from typing import Any, List
3+
from typing import Any, List, Optional
44

55

66
# types to represent log levels
@@ -304,6 +304,36 @@ def cli_msg(self) -> str:
304304
return self.msg
305305

306306

307+
@dataclass
308+
class MissingProfileTarget(InfoLevel, CliEventABC):
309+
profile_name: str
310+
target_name: str
311+
312+
def cli_msg(self) -> str:
313+
return f"target not specified in profile '{self.profile_name}', using '{self.target_name}'"
314+
315+
316+
@dataclass
317+
class ProfileLoadError(ShowException, DebugLevel, CliEventABC):
318+
exc: Exception
319+
320+
def cli_msg(self) -> str:
321+
return f"Profile not loaded due to error: {self.exc}"
322+
323+
324+
@dataclass
325+
class ProfileNotFound(InfoLevel, CliEventABC):
326+
profile_name: Optional[str]
327+
328+
def cli_msg(self) -> str:
329+
return f'No profile "{self.profile_name}" found, continuing with no target'
330+
331+
332+
class InvalidVarsYAML(ErrorLevel, CliEventABC):
333+
def cli_msg(self) -> str:
334+
return "The YAML provided in the --vars argument is not valid.\n"
335+
336+
307337
@dataclass
308338
class NewConnectionOpening(DebugLevel, CliEventABC):
309339
connection_state: str
@@ -364,3 +394,7 @@ def cli_msg(self) -> str:
364394
NewConnectionOpening(connection_state='')
365395
TimingInfoCollected()
366396
MergedFromState(nbr_merged=0, sample=[])
397+
MissingProfileTarget(profile_name='', target_name='')
398+
ProfileLoadError(exc=Exception(''))
399+
ProfileNotFound(profile_name='')
400+
InvalidVarsYAML()

0 commit comments

Comments
 (0)