Skip to content

Commit

Permalink
Fix an issue with _graph_info (#1966)
Browse files Browse the repository at this point in the history
_graph_info could contain non POD which broke things particularly in the presence of extensions
  • Loading branch information
romain-intel authored Aug 18, 2024
1 parent ee5a4db commit 5035628
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion metaflow/flowspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)
from .graph import FlowGraph
from .unbounded_foreach import UnboundedForeachInput
from .util import to_pod
from .metaflow_config import INCLUDE_FOREACH_STACK, MAXIMUM_FOREACH_VALUE_CHARS

# For Python 3 compatibility
Expand Down Expand Up @@ -201,7 +202,7 @@ def _set_constants(self, graph, kwargs):
"decorators": [
{
"name": deco.name,
"attributes": deco.attributes,
"attributes": to_pod(deco.attributes),
"statically_defined": deco.statically_defined,
}
for deco in flow_decorators(self)
Expand Down
7 changes: 4 additions & 3 deletions metaflow/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import re


from .util import to_pod


def deindent_docstring(doc):
if doc:
# Find the indent to remove from the docstring. We consider the following possibilities:
Expand Down Expand Up @@ -72,7 +75,6 @@ def _expr_str(self, expr):
return "%s.%s" % (expr.value.id, expr.attr)

def _parse(self, func_ast):

self.num_args = len(func_ast.args.args)
tail = func_ast.body[-1]

Expand Down Expand Up @@ -262,7 +264,6 @@ def node_specs():
)

def output_steps(self):

steps_info = {}
graph_structure = []

Expand All @@ -286,7 +287,7 @@ def node_to_dict(name, node):
"decorators": [
{
"name": deco.name,
"attributes": deco.attributes,
"attributes": to_pod(deco.attributes),
"statically_defined": deco.statically_defined,
}
for deco in node.decorators
Expand Down
19 changes: 19 additions & 0 deletions metaflow/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,25 @@ def is_within_directory(abs_directory, target):
tar.extractall(path, members, numeric_owner=numeric_owner)


def to_pod(value):
"""
Convert a python object to plain-old-data (POD) format.
Parameters
----------
value : Any
Value to convert to POD format. The value can be a string, number, list,
dictionary, or a nested structure of these types.
"""
if isinstance(value, (str, int, float)):
return value
if isinstance(value, dict):
return {to_pod(k): to_pod(v) for k, v in value.items()}
if isinstance(value, (list, set, tuple)):
return [to_pod(v) for v in value]
return str(value)


if sys.version_info[:2] > (3, 5):
from metaflow._vendor.packaging.version import parse as version_parse
else:
Expand Down

0 comments on commit 5035628

Please sign in to comment.