Skip to content

Commit

Permalink
better attribute resolve handling
Browse files Browse the repository at this point in the history
Signed-off-by: Future-Outlier <[email protected]>
  • Loading branch information
Future-Outlier committed Oct 4, 2024
1 parent b306b4b commit c8dd0a0
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions flytepropeller/pkg/controller/nodes/attr_path_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,27 @@ func resolveAttrPathInBinary(nodeID string, binaryIDL *core.Binary, bindAttrPath
switch resolvedVal := currVal.(type) {
// map
case map[any]any:
tmpVal, exist = resolvedVal[attr.GetStringValue()]
// TODO: for cases like Dict[int, Any] in a dataclass, this will fail,
// will support it in the future when flytekit supports it
promise, ok := attr.GetValue().(*core.PromiseAttribute_StringValue)
if !ok {
return nil, errors.Errorf(errors.PromiseAttributeResolveError, nodeID,
"unexpected attribute type [%T] for value %v", attr.GetValue(), attr.GetValue())

Check warning on line 144 in flytepropeller/pkg/controller/nodes/attr_path_resolver.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/nodes/attr_path_resolver.go#L143-L144

Added lines #L143 - L144 were not covered by tests
}
key := promise.StringValue
tmpVal, exist = resolvedVal[key]
if !exist {
return nil, errors.Errorf(errors.PromiseAttributeResolveError, nodeID, "key [%v] does not exist in literal %v", attr.GetStringValue(), currVal)
}
currVal = tmpVal
// list
case []any:
index := int(attr.GetIntValue())
promise, ok := attr.GetValue().(*core.PromiseAttribute_IntValue)
if !ok {
return nil, errors.Errorf(errors.PromiseAttributeResolveError, nodeID,
"unexpected attribute type [%T] for value %v", attr.GetValue(), attr.GetValue())

Check warning on line 157 in flytepropeller/pkg/controller/nodes/attr_path_resolver.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/nodes/attr_path_resolver.go#L156-L157

Added lines #L156 - L157 were not covered by tests
}
index := int(promise.IntValue) // convert to int64
if index < 0 || index >= len(resolvedVal) {
return nil, errors.Errorf(errors.PromiseAttributeResolveError, nodeID,
"index [%v] is out of range of %v", index, resolvedVal)
Expand All @@ -154,19 +167,13 @@ func resolveAttrPathInBinary(nodeID string, binaryIDL *core.Binary, bindAttrPath
}
}

if serializationFormat == messagepack {
// Marshal the current value to MessagePack bytes
resolvedBinaryBytes, err := msgpack.Marshal(currVal)
if err != nil {
return nil, err
}
// Construct and return the binary-encoded literal
return constructResolvedBinary(resolvedBinaryBytes, serializationFormat), nil
// Marshal the current value to MessagePack bytes
resolvedBinaryBytes, err := msgpack.Marshal(currVal)
if err != nil {
return nil, err

Check warning on line 173 in flytepropeller/pkg/controller/nodes/attr_path_resolver.go

View check run for this annotation

Codecov / codecov/patch

flytepropeller/pkg/controller/nodes/attr_path_resolver.go#L173

Added line #L173 was not covered by tests
}
// Unsupported serialization format
return nil, errors.Errorf(errors.PromiseAttributeResolveError, nodeID,
"Unsupported format '%v' found for literal value.\n"+
"Please ensure the serialization format is supported.", serializationFormat)
// Construct and return the binary-encoded literal
return constructResolvedBinary(resolvedBinaryBytes, serializationFormat), nil
}

func constructResolvedBinary(resolvedBinaryBytes []byte, serializationFormat string) *core.Literal {
Expand Down

0 comments on commit c8dd0a0

Please sign in to comment.