From 7c1922eb7322c11dd8e67d2d84277af8f53d4d65 Mon Sep 17 00:00:00 2001 From: Romain Cledat Date: Tue, 17 Dec 2024 01:40:42 -0800 Subject: [PATCH] Store configs as dictionaries --- metaflow/__init__.py | 2 +- metaflow/flowspec.py | 5 +++++ metaflow/user_configs/config_parameters.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/metaflow/__init__.py b/metaflow/__init__.py index b4f0d8d2253..418940216b5 100644 --- a/metaflow/__init__.py +++ b/metaflow/__init__.py @@ -103,7 +103,7 @@ class and related decorators. from .parameters import Parameter, JSONTypeClass, JSONType -from .user_configs.config_parameters import Config, config_expr +from .user_configs.config_parameters import Config, ConfigValue, config_expr from .user_configs.config_decorators import CustomFlowDecorator, CustomStepDecorator # data layer diff --git a/metaflow/flowspec.py b/metaflow/flowspec.py index 222c178e1a7..db09a256a12 100644 --- a/metaflow/flowspec.py +++ b/metaflow/flowspec.py @@ -24,6 +24,7 @@ from .graph import FlowGraph from .unbounded_foreach import UnboundedForeachInput from .user_configs.config_decorators import ( + ConfigValue, CustomFlowDecorator, CustomStepDecorator, MutableFlow, @@ -310,6 +311,10 @@ def _set_constants(self, graph, kwargs, config_options): if isinstance(val, DelayedEvaluationParameter): val = val() val = val.split(param.separator) if val and param.separator else val + if isinstance(val, ConfigValue): + # We store config values as dict so they are accessible with older + # metaflow clients. It also makes it easier to access. + val = val.to_dict() setattr(self, var, val) parameters_info.append({"name": var, "type": param.__class__.__name__}) diff --git a/metaflow/user_configs/config_parameters.py b/metaflow/user_configs/config_parameters.py index 18b27d84615..1eb295edb9c 100644 --- a/metaflow/user_configs/config_parameters.py +++ b/metaflow/user_configs/config_parameters.py @@ -338,7 +338,7 @@ def __init__( self._computed_value = None def load_parameter(self, v): - return v + return ConfigValue(v) def _store_value(self, v: Any) -> None: self._computed_value = v