Tree: Use safe loader for YAML

Loaders that read use a safe type while loaders that write use both
round-trip and safe options.

Also don't create module-level parsers where they're not needed.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri
2024-09-18 12:12:49 -04:00
parent 6c7542de9f
commit 24ea85b3c5
4 changed files with 18 additions and 12 deletions

View File

@@ -11,8 +11,6 @@ from typing import Dict, List, Optional, Union
from common.utils import unwrap, prune_dict
yaml = YAML()
# Common class for sampler params
class BaseSamplerRequest(BaseModel):
@@ -418,7 +416,10 @@ async def overrides_from_file(preset_name: str):
overrides_container.selected_preset = preset_path.stem
async with aiofiles.open(preset_path, "r", encoding="utf8") as raw_preset:
contents = await raw_preset.read()
preset = yaml.safe_load(contents)
# Create a temporary YAML parser
yaml = YAML(typ="safe")
preset = yaml.load(contents)
overrides_from_dict(preset)
logger.info("Applied sampler overrides from file.")