Skip to content

Commit 1a469e5

Browse files
authored
fix(query): RoleInfo from_pb should not err (#15496)
1 parent b5ce195 commit 1a469e5

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

src/meta/proto-conv/src/role_from_to_protobuf_impl.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
//! This mod is the key point about compatibility.
1616
//! Everytime update anything in this file, update the `VER` and let the tests pass.
1717
18+
use std::collections::HashSet;
19+
1820
use databend_common_meta_app as mt;
1921
use databend_common_protos::pb;
2022

@@ -35,11 +37,12 @@ impl FromToProto for mt::principal::RoleInfo {
3537

3638
Ok(mt::principal::RoleInfo {
3739
name: p.name.clone(),
38-
grants: mt::principal::UserGrantSet::from_pb(p.grants.ok_or_else(|| {
39-
Incompatible {
40-
reason: "RoleInfo.grants cannot be None".to_string(),
41-
}
42-
})?)?,
40+
grants: if let Some(grants) = p.grants {
41+
mt::principal::UserGrantSet::from_pb(grants)
42+
.unwrap_or_else(|_| mt::principal::UserGrantSet::new(vec![], HashSet::new()))
43+
} else {
44+
mt::principal::UserGrantSet::new(vec![], HashSet::new())
45+
},
4346
})
4447
}
4548

src/meta/proto-conv/src/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ const META_CHANGE_LOG: &[(u64, &str)] = &[
119119
(87, "2024-04-17: Add: UserOption::disabled"),
120120
(88, "2024-04-17: Add: SequenceMeta"),
121121
(89, "2024-04-19: Add: geometry_output_format settings"),
122+
(90, "2024-05-13: Refactor: After reader_check_msg success, RoleInfo::from_pb should not return err"),
122123
// Dear developer:
123124
// If you're gonna add a new metadata version, you'll have to add a test for it.
124125
// You could just copy an existing test file(e.g., `../tests/it/v024_table_meta.rs`)

src/meta/proto-conv/tests/it/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ mod v086_table_index;
9292
mod v087_user_option_disabled;
9393
mod v088_sequence_meta;
9494
mod v089_geometry_output_format;
95+
mod v090_role_info;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2023 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use std::collections::HashSet;
16+
17+
use databend_common_meta_app as mt;
18+
use databend_common_meta_app::principal::UserGrantSet;
19+
use minitrace::func_name;
20+
21+
use crate::common;
22+
23+
// These bytes are built when a new version in introduced,
24+
// and are kept for backward compatibility test.
25+
//
26+
// *************************************************************
27+
// * These messages should never be updated, *
28+
// * only be added when a new version is added, *
29+
// * or be removed when an old version is no longer supported. *
30+
// *************************************************************
31+
//
32+
33+
#[test]
34+
fn test_decode_v90_role() -> anyhow::Result<()> {
35+
let role_info_v90 = vec![
36+
10, 2, 114, 49, 18, 6, 160, 6, 90, 168, 6, 24, 160, 6, 90, 168, 6, 24,
37+
];
38+
39+
let want = || mt::principal::RoleInfo {
40+
name: "r1".to_string(),
41+
grants: UserGrantSet::new(vec![], HashSet::new()),
42+
};
43+
common::test_pb_from_to(func_name!(), want())?;
44+
common::test_load_old(func_name!(), role_info_v90.as_slice(), 90, want())?;
45+
46+
Ok(())
47+
}

0 commit comments

Comments
 (0)