From 9d4b349ec9f53db02eb3de557f165a801723414e Mon Sep 17 00:00:00 2001 From: Milan Lukac Date: Thu, 28 Nov 2024 11:01:12 -0800 Subject: [PATCH] Yaml: read and parse files thread-safe (#2188) --- soda/core/soda/common/yaml_helper.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/soda/core/soda/common/yaml_helper.py b/soda/core/soda/common/yaml_helper.py index 46c9a3576..e40274bb8 100644 --- a/soda/core/soda/common/yaml_helper.py +++ b/soda/core/soda/common/yaml_helper.py @@ -1,29 +1,29 @@ from ruamel.yaml import YAML, StringIO -def create_yaml() -> YAML: - yaml = YAML() - yaml.preserve_quotes = True - yaml.indent(mapping=2, sequence=4, offset=2) - return yaml - - # Deprecated. Replace all usages with YamlHelper.to_yaml below def to_yaml_str(yaml_object) -> str: return YamlHelper.to_yaml(yaml_object) class YamlHelper: - __yaml = create_yaml() + @staticmethod + def create_yaml() -> YAML: + yaml = YAML() + yaml.preserve_quotes = True + yaml.indent(mapping=2, sequence=4, offset=2) + return yaml @classmethod def to_yaml(cls, yaml_object) -> str: if yaml_object is None: return "" stream = StringIO() - cls.__yaml.dump(yaml_object, stream) + yaml = cls.create_yaml() # Create a new YAML instance for thread safety + yaml.dump(yaml_object, stream) return stream.getvalue() @classmethod def from_yaml(cls, yaml_str) -> object: - return cls.__yaml.load(yaml_str) + yaml = cls.create_yaml() # Create a new YAML instance for thread safety + return yaml.load(yaml_str)