Skip to content

Commit

Permalink
Properly compute user set attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-intel committed Jan 7, 2025
1 parent 17e29ed commit a4ae072
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions metaflow/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def init(self):
return

# Note that by design, later values override previous ones.
self.attributes = unpack_delayed_evaluator(self.attributes)
self._user_defined_attributes.update(self.attributes.keys())
self.attributes, new_user_attributes = unpack_delayed_evaluator(self.attributes)
self._user_defined_attributes.update(new_user_attributes)
self.attributes = resolve_delayed_evaluator(self.attributes)

self._ran_init = True
Expand Down
4 changes: 3 additions & 1 deletion metaflow/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ def init(self, ignore_errors=False):
)

# Resolve any value from configurations
self.kwargs = unpack_delayed_evaluator(self.kwargs, ignore_errors=ignore_errors)
self.kwargs, _ = unpack_delayed_evaluator(
self.kwargs, ignore_errors=ignore_errors
)
# Do it one item at a time so errors are ignored at that level (as opposed to
# at the entire kwargs level)
self.kwargs = {
Expand Down
11 changes: 7 additions & 4 deletions metaflow/user_configs/config_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import re

from typing import Any, Callable, Dict, Optional, TYPE_CHECKING, Union
from typing import Any, Callable, Dict, List, Optional, Tuple, TYPE_CHECKING, Union


from ..exception import MetaflowException
Expand Down Expand Up @@ -406,17 +406,20 @@ def resolve_delayed_evaluator(v: Any, ignore_errors: bool = False) -> Any:

def unpack_delayed_evaluator(
to_unpack: Dict[str, Any], ignore_errors: bool = False
) -> Dict[str, Any]:
) -> Tuple[Dict[str, Any], List[str]]:
result = {}
new_keys = []
for k, v in to_unpack.items():
if not isinstance(k, str) or not k.startswith(UNPACK_KEY):
result[k] = v
else:
# k.startswith(UNPACK_KEY)
try:
result.update(resolve_delayed_evaluator(v))
new_vals = resolve_delayed_evaluator(v)
new_keys.extend(new_vals.keys())
result.update(new_vals)
except Exception as e:
if ignore_errors:
continue
raise e
return result
return result, new_keys

0 comments on commit a4ae072

Please sign in to comment.