Skip to content

Commit 58c4ac5

Browse files
committed
fix:修复bool默认无效 --bug=150687052 【CMDB】[前端]业务拓扑中自定义字段bool字段默认值无效
# Conflicts: # src/scene_server/admin_server/imports.go
1 parent 0561f7d commit 58c4ac5

4 files changed

Lines changed: 103 additions & 3 deletions

File tree

src/scene_server/admin_server/imports.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,6 @@ import (
120120
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202405141035"
121121
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202410100930"
122122
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202502101200"
123+
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202603161200"
123124
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202603231000"
124125
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making
3+
* 蓝鲸智云 - 配置平台 (BlueKing - Configuration System) available.
4+
* Copyright (C) 2017 Tencent. All rights reserved.
5+
* Licensed under the MIT License (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at http://opensource.org/licenses/MIT
8+
* Unless required by applicable law or agreed to in writing,
9+
* software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* We undertake not to change the open source license (MIT license) applicable
14+
* to the current version of the project delivered to anyone in the future.
15+
*/
16+
17+
package y3_14_202603161200
18+
19+
import (
20+
"context"
21+
22+
"configcenter/src/common/blog"
23+
"configcenter/src/scene_server/admin_server/upgrader"
24+
"configcenter/src/storage/dal"
25+
)
26+
27+
func init() {
28+
upgrader.RegistUpgrader("y3.14.202603161200", upgrade)
29+
}
30+
31+
func upgrade(ctx context.Context, db dal.RDB, conf *upgrader.Config) (err error) {
32+
33+
blog.Infof("start execute y3.14.202603161200")
34+
err = upsertObjAttDesBoolDefaultValue(ctx, db, conf)
35+
if err != nil {
36+
blog.Errorf("upgrade y3.14.202603161200 add host os kernel version field failed, error: %v", err)
37+
return err
38+
}
39+
blog.Infof("execute y3.14.202603161200, add host os kernel version field success!")
40+
41+
return nil
42+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making
3+
* 蓝鲸智云 - 配置平台 (BlueKing - Configuration System) available.
4+
* Copyright (C) 2017 Tencent. All rights reserved.
5+
* Licensed under the MIT License (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at http://opensource.org/licenses/MIT
8+
* Unless required by applicable law or agreed to in writing,
9+
* software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11+
* either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* We undertake not to change the open source license (MIT license) applicable
14+
* to the current version of the project delivered to anyone in the future.
15+
*/
16+
17+
package y3_14_202603161200
18+
19+
import (
20+
"configcenter/src/common"
21+
"configcenter/src/common/blog"
22+
"configcenter/src/scene_server/admin_server/upgrader"
23+
"configcenter/src/storage/dal"
24+
"context"
25+
26+
"go.mongodb.org/mongo-driver/bson"
27+
)
28+
29+
// upsertObjAttDesBoolDefaultValue
30+
//
31+
//option:true ->default:true
32+
//option:false or default:null ->default:false
33+
func upsertObjAttDesBoolDefaultValue(ctx context.Context, db dal.RDB, conf *upgrader.Config) error {
34+
updateCond := bson.M{
35+
common.BKPropertyTypeField: common.FieldTypeBool,
36+
common.BKDBOR: bson.A{
37+
bson.M{common.BKOptionField: false},
38+
bson.M{common.BKDefaultField: nil},
39+
},
40+
}
41+
updateData := map[string]interface{}{common.BKDefaultField: false}
42+
if err := db.Table(common.BKTableNameObjAttDes).Update(ctx, updateCond, updateData); err != nil {
43+
blog.Errorf("update bool attribute failed, err: %v, cond: %v, updateData: %v", err, updateCond,
44+
updateData)
45+
return err
46+
}
47+
48+
updateCond = bson.M{common.BKOptionField: true}
49+
updateData = map[string]interface{}{common.BKDefaultField: true}
50+
if err := db.Table(common.BKTableNameObjAttDes).Update(ctx, updateCond, updateData); err != nil {
51+
blog.Errorf("update bool attribute failed, err: %v, cond: %v, updateData: %v", err, updateCond,
52+
updateData)
53+
return err
54+
}
55+
56+
return nil
57+
}

src/source_controller/coreservice/core/instances/validator_util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,13 @@ func fillLostListFieldValue(valData mapstr.MapStr, field metadata.Attribute) err
356356
func fillLostBoolFieldValue(valData mapstr.MapStr, field metadata.Attribute) error {
357357
valData[field.PropertyID] = false
358358
if field.Default == nil {
359-
return nil
359+
field.Default = false
360+
field.Option = false
360361
}
361-
362+
field.Option = field.Default
362363
if err := valid.ValidateBoolType(field.Default); err != nil {
363364
return err
364365
}
365-
366366
valData[field.PropertyID] = field.Default
367367
return nil
368368
}

0 commit comments

Comments
 (0)