Skip to content

Commit cc10623

Browse files
committed
fix(query): Gracefully handle unknown GrantEntry objects in UserGrantSet::from_pb
When an older version of the application processes `UserGrantSet` data that contains `GrantEntry` objects with newly introduced `GrantObject` types, the `GrantEntry::from_pb` conversion can fail for those specific entries. This commit modifies the `UserGrantSet::from_pb` function to gracefully handle such scenarios. If `GrantEntry::from_pb` returns an error (e.g., due to an unknown `GrantObject`), the error is now logged, and the problematic grant entry is skipped instead of causing the entire conversion to fail. This ensures that users on older versions can still log in and use their available grants, providing better forward compatibility and robustness against evolving data schemas. Without this, a user attempting to log in with data containing new `GrantObject` types would be prevented from logging in on an older client.
1 parent d6ddbae commit cc10623

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/meta/proto-conv/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ databend-common-meta-types = { workspace = true }
1616
databend-common-protos = { workspace = true }
1717
enumflags2 = { workspace = true }
1818
fastrace = { workspace = true }
19+
log = { workspace = true }
1920
num = { workspace = true }
2021
prost = { workspace = true }
2122
thiserror = { workspace = true }

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,13 @@ impl FromToProto for mt::principal::UserGrantSet {
295295

296296
let mut entries = Vec::new();
297297
for entry in p.entries.iter() {
298-
entries.push(mt::principal::GrantEntry::from_pb(entry.clone())?);
298+
// If we add new GrantObject in new version
299+
// Rollback to old version, GrantEntry.object will be None
300+
// GrantEntry::from_pb will return err so user can not login in old version.
301+
match mt::principal::GrantEntry::from_pb(entry.clone()) {
302+
Ok(entry) => entries.push(entry),
303+
Err(e) => log::error!("GrantEntry::from_pb with error : {e}"),
304+
}
299305
}
300306
let mut roles = HashSet::new();
301307
for role in p.roles.iter() {

0 commit comments

Comments
 (0)