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

respect aliases when loading custom logging.yaml #17162

Merged
merged 2 commits into from
Feb 20, 2025
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
4 changes: 3 additions & 1 deletion src/prefect/logging/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def load_logging_config(path: Path) -> dict[str, Any]:
warnings.filterwarnings("ignore", category=DeprecationWarning)
config = yaml.safe_load(
# Substitute settings into the template in format $SETTING / ${SETTING}
template.substitute(current_settings.to_environment_variables())
template.substitute(
current_settings.to_environment_variables(include_aliases=True)
)
)

# Load overrides from the environment
Expand Down
21 changes: 18 additions & 3 deletions src/prefect/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def to_environment_variables(
self,
exclude_unset: bool = False,
include_secrets: bool = True,
include_aliases: bool = False,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

important diff

) -> Dict[str, str]:
"""Convert the settings object to a dictionary of environment variables."""
env: Dict[str, Any] = self.model_dump(
Expand All @@ -105,12 +106,26 @@ def to_environment_variables(
child_env = child_settings.to_environment_variables(
exclude_unset=exclude_unset,
include_secrets=include_secrets,
include_aliases=include_aliases,
)
env_variables.update(child_env)
elif (value := env.get(key)) is not None:
env_variables[f"{self.model_config.get('env_prefix')}{key.upper()}"] = (
_to_environment_variable_value(value)
)
validation_alias = self.model_fields[key].validation_alias
if include_aliases and validation_alias is not None:
if isinstance(validation_alias, AliasChoices):
for alias in validation_alias.choices:
if isinstance(alias, str):
env_variables[alias.upper()] = (
_to_environment_variable_value(value)
)
elif isinstance(validation_alias, str):
env_variables[validation_alias.upper()] = (
_to_environment_variable_value(value)
)
else:
env_variables[
f"{self.model_config.get('env_prefix')}{key.upper()}"
] = _to_environment_variable_value(value)
return env_variables

@model_serializer(
Expand Down
Loading
Loading