From 4f61f4ee22a12911ad2b025fa4568566d1da0f37 Mon Sep 17 00:00:00 2001 From: Bingyi Sun Date: Sun, 28 Sep 2025 11:09:04 +0800 Subject: [PATCH] fix: Alter allow_insert_autoid via AlterCollection (#44530) issue: #44425 --------- Signed-off-by: sunby --- internal/proxy/task.go | 28 +++++++++++++++------------- internal/proxy/task_test.go | 15 +++++++-------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/internal/proxy/task.go b/internal/proxy/task.go index 7397f55d33..e71f0bf637 100644 --- a/internal/proxy/task.go +++ b/internal/proxy/task.go @@ -1159,6 +1159,10 @@ func (t *alterCollectionTask) PreExecute(ctx context.Context) error { return merr.WrapErrParameterInvalidMsg("cannot provide both DeleteKeys and ExtraParams") } + collSchema, err := globalMetaCache.GetCollectionSchema(ctx, t.GetDbName(), t.CollectionName) + if err != nil { + return err + } collectionID, err := globalMetaCache.GetCollectionID(ctx, t.GetDbName(), t.CollectionName) if err != nil { return err @@ -1176,6 +1180,17 @@ func (t *alterCollectionTask) PreExecute(ctx context.Context) error { return merr.WrapErrCollectionLoaded(t.CollectionName, "can not alter mmap properties if collection loaded") } } + + enabled, _ := common.IsAllowInsertAutoID(t.Properties...) + if enabled { + primaryFieldSchema, err := typeutil.GetPrimaryFieldSchema(collSchema.CollectionSchema) + if err != nil { + return err + } + if !primaryFieldSchema.AutoID { + return merr.WrapErrParameterInvalidMsg("the value for %s must be false when autoID is false", common.AllowInsertAutoIDKey) + } + } // Check the validation of timezone err := checkTimezone(t.Properties...) if err != nil { @@ -1343,7 +1358,6 @@ var allowedAlterProps = []string{ common.MaxLengthKey, common.MmapEnabledKey, common.MaxCapacityKey, - common.AllowInsertAutoIDKey, } var allowedDropProps = []string{ @@ -1473,18 +1487,6 @@ func (t *alterCollectionFieldTask) PreExecute(ctx context.Context) error { if maxCapacityPerRow > defaultMaxArrayCapacity || maxCapacityPerRow <= 0 { return merr.WrapErrParameterInvalidMsg("the maximum capacity specified for a Array should be in (0, %d]", defaultMaxArrayCapacity) } - case common.AllowInsertAutoIDKey: - allowInsertAutoID, err := strconv.ParseBool(prop.Value) - if err != nil { - return merr.WrapErrParameterInvalidMsg("the value for %s must be a boolean", common.AllowInsertAutoIDKey) - } - primaryFieldSchema, err := typeutil.GetPrimaryFieldSchema(collSchema.CollectionSchema) - if err != nil { - return err - } - if allowInsertAutoID && !primaryFieldSchema.AutoID { - return merr.WrapErrParameterInvalidMsg("the value for %s must be false when autoID is false", common.AllowInsertAutoIDKey) - } } } diff --git a/internal/proxy/task_test.go b/internal/proxy/task_test.go index 9112f53956..c8f2e9ee0d 100644 --- a/internal/proxy/task_test.go +++ b/internal/proxy/task_test.go @@ -462,8 +462,8 @@ func TestAlterCollection_AllowInsertAutoID_Validation(t *testing.T) { err := InitMetaCache(ctx, root, mgr) assert.NoError(t, err) - task := &alterCollectionFieldTask{ - AlterCollectionFieldRequest: &milvuspb.AlterCollectionFieldRequest{ + task := &alterCollectionTask{ + AlterCollectionRequest: &milvuspb.AlterCollectionRequest{ Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_AlterCollectionField}, DbName: dbName, CollectionName: "allow_autoid_test", @@ -484,8 +484,8 @@ func TestAlterCollection_AllowInsertAutoID_Validation(t *testing.T) { err := InitMetaCache(ctx, root, mgr) assert.NoError(t, err) - task := &alterCollectionFieldTask{ - AlterCollectionFieldRequest: &milvuspb.AlterCollectionFieldRequest{ + task := &alterCollectionTask{ + AlterCollectionRequest: &milvuspb.AlterCollectionRequest{ Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_AlterCollectionField}, DbName: dbName, CollectionName: "allow_autoid_test", @@ -5341,7 +5341,7 @@ func TestDescribeCollectionTaskWithStructArrayField(t *testing.T) { }) } -func TestAlterCollectionField_AllowInsertAutoID_AutoIDFalse(t *testing.T) { +func TestAlterCollection_AllowInsertAutoID_AutoIDFalse(t *testing.T) { qc := NewMixCoordMock() InitMetaCache(context.Background(), qc, nil) ctx := context.Background() @@ -5364,11 +5364,10 @@ func TestAlterCollectionField_AllowInsertAutoID_AutoIDFalse(t *testing.T) { } qc.CreateCollection(ctx, createColReq) - task := &alterCollectionFieldTask{ - AlterCollectionFieldRequest: &milvuspb.AlterCollectionFieldRequest{ + task := &alterCollectionTask{ + AlterCollectionRequest: &milvuspb.AlterCollectionRequest{ Base: &commonpb.MsgBase{}, CollectionName: collectionName, - FieldName: "", Properties: []*commonpb.KeyValuePair{ {Key: common.AllowInsertAutoIDKey, Value: "true"}, },