-
Notifications
You must be signed in to change notification settings - Fork 698
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
Flyteadmin digest comparison should rely on database semantics #6058
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -99,6 +99,67 @@ func TestCreateTask(t *testing.T) { | |||||
assert.NotNil(t, response) | ||||||
} | ||||||
|
||||||
func TestCreateTask_DuplicateTaskRegistration(t *testing.T) { | ||||||
mockRepository := getMockTaskRepository() | ||||||
mockRepository.TaskRepo().(*repositoryMocks.MockTaskRepo).SetGetCallback( | ||||||
func(input interfaces.Identifier) (models.Task, error) { | ||||||
return models.Task{ | ||||||
TaskKey: models.TaskKey{ | ||||||
Project: taskIdentifier.GetProject(), | ||||||
Domain: taskIdentifier.GetDomain(), | ||||||
Name: taskIdentifier.GetName(), | ||||||
Version: taskIdentifier.GetVersion(), | ||||||
}, | ||||||
Digest: []byte{ | ||||||
0xbf, 0x79, 0x61, 0x1c, 0xf5, 0xc1, 0xfb, 0x4c, 0xf8, 0xf4, 0xc4, 0x53, 0x5f, 0x8f, 0x73, 0xe2, 0x26, 0x5a, | ||||||
0x18, 0x4a, 0xb7, 0x66, 0x98, 0x3c, 0xab, 0x2, 0x6c, 0x9, 0x9b, 0x90, 0xec, 0x8f}, | ||||||
}, nil | ||||||
}) | ||||||
mockRepository.TaskRepo().(*repositoryMocks.MockTaskRepo).SetCreateCallback(func(input models.Task, descriptionEntity *models.DescriptionEntity) error { | ||||||
return adminErrors.NewFlyteAdminErrorf(codes.AlreadyExists, "task already exists") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding more error details
Consider making the error message more descriptive by including task identifier details in Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #ec8f77 Is this a valid issue, or was it incorrectly flagged by the Agent?
|
||||||
}) | ||||||
taskManager := NewTaskManager(mockRepository, getMockConfigForTaskTest(), getMockTaskCompiler(), | ||||||
mockScope.NewTestScope()) | ||||||
request := testutils.GetValidTaskRequest() | ||||||
_, err := taskManager.CreateTask(context.Background(), request) | ||||||
assert.Error(t, err) | ||||||
flyteErr, ok := err.(adminErrors.FlyteAdminError) | ||||||
assert.True(t, ok, "Error should be of type FlyteAdminError") | ||||||
assert.Equal(t, codes.AlreadyExists, flyteErr.Code(), "Error code should be AlreadyExists") | ||||||
assert.Contains(t, flyteErr.Error(), "task with identical structure already exists") | ||||||
differentTemplate := &core.TaskTemplate{ | ||||||
Id: &core.Identifier{ | ||||||
ResourceType: core.ResourceType_TASK, | ||||||
Project: "project", | ||||||
Domain: "domain", | ||||||
Name: "name", | ||||||
Version: "version", | ||||||
}, | ||||||
Type: "type", | ||||||
Metadata: &core.TaskMetadata{ | ||||||
Runtime: &core.RuntimeMetadata{ | ||||||
Version: "runtime version 2", | ||||||
}, | ||||||
}, | ||||||
Interface: &core.TypedInterface{}, | ||||||
Target: &core.TaskTemplate_Container{ | ||||||
Container: &core.Container{ | ||||||
Image: "image", | ||||||
Command: []string{ | ||||||
"command", | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
} | ||||||
request.Spec.Template = differentTemplate | ||||||
_, err = taskManager.CreateTask(context.Background(), request) | ||||||
assert.Error(t, err) | ||||||
flyteErr, ok = err.(adminErrors.FlyteAdminError) | ||||||
assert.True(t, ok, "Error should be of type FlyteAdminError") | ||||||
assert.Equal(t, codes.InvalidArgument, flyteErr.Code(), "Error code should be InvalidArgument") | ||||||
assert.Contains(t, flyteErr.Error(), "name task with different structure already exists.") | ||||||
} | ||||||
|
||||||
func TestCreateTask_ValidationError(t *testing.T) { | ||||||
mockRepository := getMockTaskRepository() | ||||||
taskManager := NewTaskManager(mockRepository, getMockConfigForTaskTest(), getMockTaskCompiler(), | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,12 +30,12 @@ func (r *TaskRepo) Create(ctx context.Context, input models.Task, descriptionEnt | |
} | ||
return nil | ||
} | ||
tx := r.db.WithContext(ctx).Omit("id").Create(descriptionEntity) | ||
tx := r.db.WithContext(ctx).Omit("id").Create(&input) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this change is technically not necessary since this is all wrapped in a transaction, and if any insert fails then the whole transaction should be rolled back. |
||
if tx.Error != nil { | ||
return r.errorTransformer.ToFlyteAdminError(tx.Error) | ||
} | ||
|
||
tx = r.db.WithContext(ctx).Omit("id").Create(&input) | ||
tx = r.db.WithContext(ctx).Omit("id").Create(descriptionEntity) | ||
if tx.Error != nil { | ||
return r.errorTransformer.ToFlyteAdminError(tx.Error) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using
logger.Debugf
instead oflogger.Errorf
for non-critical database errors. The error is already being returned to the caller.Code suggestion
Code Review Run #ec8f77
Is this a valid issue, or was it incorrectly flagged by the Agent?