Skip to content

Bug: Configuration.from_yaml() cannot read properly template strings in a yaml file #857

Closed
@ITHwang

Description

@ITHwang

Hi, I'm using Configuration.from_yaml() to read template strings in a yaml file like below:

template_string:  |-
  Hi! My name is ${name}.
  I'm ${age} years old.
  I'm living in ${country}.

And When I read the yaml file, the variables string in the yaml file disappear.

class Container(DeclarativeContainer):
    config = Configuration()
    config.from_yaml(yaml_dir / "introduce.yaml")
    ...

container = Container()
print(container.config.template_string())
# Hi! My name is .\nI'm years old.\nI'm living in .

But when I use pyyaml directly, it doesn't have any problem.

class Container(DeclarativeContainer):
    config = Configuration()
    config.from_pydantic(PydanticConfig())

    # config.from_yaml(yaml_dir / "introduce.yaml")
    introduce_yaml_path = yaml_dir / "introduce.yaml"
    with open(introduce_yaml_path, "r") as f:
        loaded = yaml.safe_load(f)
        config.from_dict(loaded)

print(container.config.template_string())
# Hi! My name is ${name}.\nI'm ${age} years old.\nI'm living in ${country}.

Could you guys clear up what happens in from_yaml()?
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions