Skip to content

Commit 314d6f4

Browse files
authored
[Ready for review] Add explicit max length control for foreach value. (#1733)
* add explicit max length * make foreach value string len max a configurable thing
1 parent 2bb998b commit 314d6f4

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

metaflow/flowspec.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818
from .graph import FlowGraph
1919
from .unbounded_foreach import UnboundedForeachInput
20-
from .metaflow_config import INCLUDE_FOREACH_STACK
20+
from .metaflow_config import INCLUDE_FOREACH_STACK, MAXIMUM_FOREACH_VALUE_CHARS
2121

2222
# For Python 3 compatibility
2323
try:
@@ -529,7 +529,7 @@ def _is_primitive_type(item):
529529
)
530530

531531
value = item if _is_primitive_type(item) else reprlib.Repr().repr(item)
532-
return basestring(value)
532+
return basestring(value)[:MAXIMUM_FOREACH_VALUE_CHARS]
533533

534534
def next(self, *dsts: Callable[..., None], **kwargs) -> None:
535535
"""

metaflow/metaflow_config.py

+2
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@
205205
# Controls whether to include foreach stack information in metadata.
206206
# TODO(Darin, 05/01/24): Remove this flag once we are confident with this feature.
207207
INCLUDE_FOREACH_STACK = from_conf("INCLUDE_FOREACH_STACK", False)
208+
# Maximum length of the foreach value string to be stored in each ForeachFrame.
209+
MAXIMUM_FOREACH_VALUE_CHARS = from_conf("MAXIMUM_FOREACH_VALUE_CHARS", 30)
208210

209211
###
210212
# Organization customizations

0 commit comments

Comments
 (0)