Skip to content

Add primitive_or_expr() back to conditions #3293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/sagemaker/workflow/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import abc

from enum import Enum
from typing import List, Union
from typing import Dict, List, Union

import attr

from sagemaker.workflow import is_pipeline_variable
from sagemaker.workflow.entities import (
DefaultEnumMeta,
Entity,
Expression,
PrimitiveType,
RequestType,
)
Expand Down Expand Up @@ -289,3 +291,18 @@ def _referenced_steps(self) -> List[str]:
for condition in self.conditions:
steps.extend(condition._referenced_steps)
return steps


def primitive_or_expr(
value: Union[ExecutionVariable, Expression, PrimitiveType, Parameter, Properties]
) -> Union[Dict[str, str], PrimitiveType]:
"""Provide the expression of the value or return value if it is a primitive.

Args:
value (Union[ConditionValueType, PrimitiveType]): The value to evaluate.
Returns:
Either the expression of the value or the primitive value.
"""
if is_pipeline_variable(value):
return value.expr
return value