Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriyK90 committed Jan 11, 2024
1 parent bafe365 commit 98d9fc6
Showing 1 changed file with 1 addition and 44 deletions.
45 changes: 1 addition & 44 deletions cosmos/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ class ProfileConfig:
:param target_name: The name of the dbt target to use.
:param profiles_yml_filepath: The path to a profiles.yml file to use.
:param profile_mapping: A mapping of Airflow connections to dbt profiles.
:param dbt_config_vars: Dictionary of dbt configs for the project. This argument overrides configs defined in your profiles.yml
file. The dictionary is dumped to a yaml string. Details https://docs.getdbt.com/docs/core/connect-data-platform/profiles.yml
"""

# should always be set to be explicit
Expand All @@ -225,11 +223,9 @@ class ProfileConfig:

# should be set if using cosmos to map Airflow connections to dbt profiles
profile_mapping: BaseProfileMapping | None = None
dbt_config_vars: dict[str, Any] | None = None

def __post_init__(self) -> None:
self.validate_profile()
self.validate_dbt_config_vars()

def validate_profile(self) -> None:
"Validates that we have enough information to render a profile."
Expand All @@ -240,42 +236,6 @@ def validate_profile(self) -> None:
"Both profiles_yml_filepath and profile_mapping are defined and are mutually exclusive. Ensure only one of these is defined."
)

def validate_dbt_config_vars(self) -> None:
"Validates config vars for profile."

vars_checks: dict[str, dict[str, Any]] = {
"send_anonymous_usage_stats": {"var_type": bool},
"use_colors": {"var_type": bool},
"partial_parse": {"var_type": bool},
"printer_width": {"var_type": int},
"write_json": {"var_type": bool},
"warn_error": {"var_type": str},
"log_format": {"var_type": str, "accepted_values": {"text", "json", "default"}},
"debug": {"var_type": bool},
"version_check": {"var_type": bool},
"fail_fast": {"var_type": bool},
"use_experimental_parser": {"var_type": bool},
"static_parser": {"var_type": bool},
}

if self.dbt_config_vars:
for var_key, var_value in self.dbt_config_vars.items():
vars_check = vars_checks.get(var_key)
if vars_check:
var_type = vars_check.get("var_type")
if var_type:
if not isinstance(var_value, var_type):
raise CosmosValueError(f"dbt config var {var_key}: {var_value} must be a {var_type}")

accepted_values = vars_check.get("accepted_values")
if accepted_values:
if var_value not in accepted_values:
raise CosmosValueError(
f"dbt config var {var_key}: {var_value} must be one of {accepted_values}"
)
else:
warnings.warn(f"dbt config var {var_key}: {var_value} is not supported")

def validate_profiles_yml(self) -> None:
"Validates a user-supplied profiles.yml is present"
if self.profiles_yml_filepath and not Path(self.profiles_yml_filepath).exists():
Expand All @@ -292,10 +252,7 @@ def ensure_profile(

elif self.profile_mapping:
profile_contents = self.profile_mapping.get_profile_file_contents(
profile_name=self.profile_name,
target_name=self.target_name,
use_mock_values=use_mock_values,
dbt_config_vars=self.dbt_config_vars,
profile_name=self.profile_name, target_name=self.target_name, use_mock_values=use_mock_values
)

if use_mock_values:
Expand Down

0 comments on commit 98d9fc6

Please sign in to comment.