Skip to content
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

stripping metadata from dataclass types (#626) #6177

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 9 additions & 3 deletions flytepropeller/pkg/compiler/transformers/k8s/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,15 @@ func StripTypeMetadata(t *core.LiteralType) *core.LiteralType {
}
}

// Note that we cannot strip `Structure` from the type because the dynamic node output type is used to validate the
// interface of the dynamically compiled workflow. `Structure` is used to extend type checking information on
// different Flyte types and is therefore required to ensure correct type validation.
// strip metadata from dataclass types
if c.Structure != nil && len(c.Structure.DataclassType) > 0 {
dataclassTypes := make(map[string]*core.LiteralType, len(c.Structure.DataclassType))
for k, v := range c.Structure.DataclassType {
dataclassTypes[k] = StripTypeMetadata(v)
}

c.Structure.DataclassType = dataclassTypes
}

switch underlyingType := c.GetType().(type) {
case *core.LiteralType_UnionType:
Expand Down
31 changes: 29 additions & 2 deletions flytepropeller/pkg/compiler/transformers/k8s/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,25 @@ func TestStripTypeMetadata(t *testing.T) {
},
},
},
Structure: &core.TypeStructure{Tag: "str"},
Structure: &core.TypeStructure{
DataclassType: map[string]*core.LiteralType{
"foo": {
Type: &core.LiteralType_Simple{
Simple: core.SimpleType_STRING,
},
Metadata: &_struct.Struct{
Fields: map[string]*_struct.Value{
"foo": {
Kind: &_struct.Value_StringValue{
StringValue: "bar",
},
},
},
},
},
},
Tag: "str",
},
},
},
},
Expand All @@ -241,7 +259,16 @@ func TestStripTypeMetadata(t *testing.T) {
Type: &core.LiteralType_Simple{
Simple: core.SimpleType_STRING,
},
Structure: &core.TypeStructure{Tag: "str"},
Structure: &core.TypeStructure{
DataclassType: map[string]*core.LiteralType{
"foo": {
Type: &core.LiteralType_Simple{
Simple: core.SimpleType_STRING,
},
},
},
Tag: "str",
},
Comment on lines +262 to +271
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider simplifying nested structure initialization

Consider simplifying the nested structure by using a more concise initialization pattern for TypeStructure. The current nested structure with multiple levels of indentation could be made more readable. A similar issue was also found in flytepropeller/pkg/compiler/transformers/k8s/utils_test.go (line 227-245).

Code suggestion
Check the AI-generated fix before applying
 // Add helper function
 func createTypeStructure(key string, simpleType core.SimpleType, tag string) *core.TypeStructure {
     return &core.TypeStructure{
         DataclassType: map[string]*core.LiteralType{
             key: {
                 Type: &core.LiteralType_Simple{Simple: simpleType},
             },
         },
         Tag: tag,
     }
 }

 // Use helper function in test
 Structure: createTypeStructure("foo", core.SimpleType_STRING, "str"),

Code Review Run #59e151


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

},
},
},
Expand Down
Loading