Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: fix the nil pointer error (#14302)

rebelice7185ca462e0d
diff --git a/backend/plugin/advisor/pg/advisor_statement_object_owner_check.go b/backend/plugin/advisor/pg/advisor_statement_object_owner_check.go
index 2591b852e0..8d30efaf9b 100644
--- a/backend/plugin/advisor/pg/advisor_statement_object_owner_check.go
+++ b/backend/plugin/advisor/pg/advisor_statement_object_owner_check.go
@@ -484,21 +484,44 @@ func (*StatementObjectOwnerCheckAdvisor) Check(ctx advisor.Context, _ string) ([
if schemaMeta == nil {
continue
}
- tableMeta := schemaMeta.GetTable(table.Name)
- owner := tableMeta.GetOwner()
- if owner == pgDatabaseOwner {
- owner = dbMetadata.GetOwner()
- }
- if owner != currentRole {
- adviceList = append(adviceList, &storepb.Advice{
- Status: level,
- Title: title,
- Content: fmt.Sprintf("Table \"%s\" is owned by \"%s\", but the current role is \"%s\".", table.Name, owner, currentRole),
- Code: advisor.StatementObjectOwnerCheck.Int32(),
- StartPosition: &storepb.Position{
- Line: int32(stmt.LastLine()),
- },
- })
+ switch table.Type {
+ case ast.TableTypeBaseTable:
+ tableMeta := schemaMeta.GetTable(table.Name)
+ if tableMeta == nil {
+ continue
+ }
+ owner := tableMeta.GetOwner()
+ if owner == pgDatabaseOwner {
+ owner = dbMetadata.GetOwner()
+ }
+ if owner != currentRole {
+ adviceList = append(adviceList, &storepb.Advice{
+ Status: level,
+ Title: title,
+ Content: fmt.Sprintf("Table \"%s\" is owned by \"%s\", but the current role is \"%s\".", table.Name, owner, currentRole),
+ Code: advisor.StatementObjectOwnerCheck.Int32(),
+ StartPosition: &storepb.Position{
+ Line: int32(stmt.LastLine()),
+ },
+ })
+ }
+ default:
+ // todo: use view owner instead of schema owner
+ owner := schemaMeta.GetOwner()
+ if owner == pgDatabaseOwner {
+ owner = dbMetadata.GetOwner()
+ }
+ if owner != currentRole {
+ adviceList = append(adviceList, &storepb.Advice{
+ Status: level,
+ Title: title,
+ Content: fmt.Sprintf("Schema \"%s\" is owned by \"%s\", but the current role is \"%s\".", schemaName, owner, currentRole),
+ Code: advisor.StatementObjectOwnerCheck.Int32(),
+ StartPosition: &storepb.Position{
+ Line: int32(stmt.LastLine()),
+ },
+ })
+ }
}
}
case *ast.DropTriggerStmt:
diff --git a/backend/store/model/database.go b/backend/store/model/database.go
index b3e52a029e..70e051b51f 100644
--- a/backend/store/model/database.go
+++ b/backend/store/model/database.go
@@ -449,6 +449,9 @@ type SchemaMetadata struct {
}
func (s *SchemaMetadata) GetOwner() string {
+ if s.proto == nil {
+ return ""
+ }
return s.proto.Owner
}