Skip to content

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

fix(spanner): set query span Type to Select on the SELECT path (#20502)

h3n4l0dd022d53136
diff --git a/backend/plugin/parser/spanner/query_span_extractor.go b/backend/plugin/parser/spanner/query_span_extractor.go
index e10588ffa7..150a4b1e57 100644
--- a/backend/plugin/parser/spanner/query_span_extractor.go
+++ b/backend/plugin/parser/spanner/query_span_extractor.go
@@ -81,6 +81,7 @@ func (q *querySpanExtractor) getQuerySpan(ctx context.Context, stmt string) (*ba
}
return &base.QuerySpan{
+ Type: base.Select,
Results: querySpanResult,
SourceColumns: accessTables,
}, nil
diff --git a/backend/plugin/parser/spanner/query_span_type_test.go b/backend/plugin/parser/spanner/query_span_type_test.go
new file mode 100644
index 0000000000..afde8b495d
--- /dev/null
+++ b/backend/plugin/parser/spanner/query_span_type_test.go
@@ -0,0 +1,33 @@
+package spanner
+
+import (
+ "context"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
+ "github.com/bytebase/bytebase/backend/plugin/parser/base"
+)
+
+// TestQuerySpanTypeForSelect guards BYT-9627: a SELECT must produce a query
+// span with Type == base.Select. Spanner is in EngineSupportQueryNewACL, where
+// the access check rejects a QueryTypeUnknown span as "disallowed query type",
+// so a missing Type makes every Spanner SELECT fail in normal (non-admin) mode.
+func TestQuerySpanTypeForSelect(t *testing.T) {
+ getter, lister := buildMockDatabaseMetadataGetter([]*storepb.DatabaseSchemaMetadata{{Name: "db"}})
+ result, err := GetQuerySpan(
+ context.Background(),
+ base.GetQuerySpanContext{
+ GetDatabaseMetadataFunc: getter,
+ ListDatabaseNamesFunc: lister,
+ },
+ base.Statement{Text: "SELECT 1"},
+ "db",
+ "",
+ false,
+ )
+ require.NoError(t, err)
+ require.Equal(t, base.Select, result.Type,
+ "a plain SELECT must have query span Type=Select; otherwise the new-ACL access check rejects it as \"disallowed query type\"")
+}
diff --git a/backend/plugin/parser/spanner/test-data/query-span/standard.yaml b/backend/plugin/parser/spanner/test-data/query-span/standard.yaml
index 60c2352d87..8485d92c8d 100644
--- a/backend/plugin/parser/spanner/test-data/query-span/standard.yaml
+++ b/backend/plugin/parser/spanner/test-data/query-span/standard.yaml
@@ -37,7 +37,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: Id
sourcecolumns:
@@ -107,7 +107,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: NAME
sourcecolumns:
@@ -163,7 +163,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: ID
sourcecolumns:
@@ -257,7 +257,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: ID
sourcecolumns:
@@ -341,7 +341,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: ID
sourcecolumns:
@@ -422,7 +422,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: ID
sourcecolumns:
@@ -501,7 +501,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: C1
sourcecolumns:
@@ -596,7 +596,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: ID
sourcecolumns:
@@ -673,7 +673,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: CITY
sourcecolumns:
@@ -728,7 +728,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: ""
sourcecolumns: []
@@ -778,7 +778,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: ID
sourcecolumns:
@@ -848,7 +848,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: Id
sourcecolumns:
@@ -903,7 +903,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: ID
sourcecolumns:
@@ -958,7 +958,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: ID
sourcecolumns:
@@ -1033,7 +1033,7 @@
]
}
querySpan:
- type: 0
+ type: 1
results:
- name: Id
sourcecolumns: