Skip to content

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

chore: refuse empty data source id in SQLService.Query (#16124)

h3n4l1478102a42a2
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
index 9cc659fdb5..ffc21ca0cf 100644
--- a/backend/api/v1/sql_service.go
+++ b/backend/api/v1/sql_service.go
@@ -1888,23 +1888,10 @@ func checkAndGetDataSourceQueriable(ctx context.Context, storeInstance *store.St
if instance == nil {
return nil, errors.Errorf("instance %q not found", database.InstanceID)
}
+ if dataSourceID == "" {
+ return nil, status.Errorf(codes.InvalidArgument, "data source id is required")
+ }
dataSource, serr := func() (*storepb.DataSource, *status.Status) {
- // dataSourceID unspecified, we find a readonly dataSource
- // first and fallback to admin dataSource.
- if dataSourceID == "" {
- for _, ds := range instance.Metadata.GetDataSources() {
- if ds.GetType() == storepb.DataSourceType_READ_ONLY {
- return ds, nil
- }
- }
- for _, ds := range instance.Metadata.GetDataSources() {
- if ds.GetType() == storepb.DataSourceType_ADMIN {
- return ds, nil
- }
- }
- return nil, status.Newf(codes.FailedPrecondition, "no data source found")
- }
-
for _, ds := range instance.Metadata.GetDataSources() {
if ds.GetId() == dataSourceID {
return ds, nil
diff --git a/backend/tests/sql_export_test.go b/backend/tests/sql_export_test.go
index 3297988e9e..23256553d0 100644
--- a/backend/tests/sql_export_test.go
+++ b/backend/tests/sql_export_test.go
@@ -182,6 +182,10 @@ func TestSQLExport(t *testing.T) {
})
a.NoError(err)
+ a.NotNil(database.InstanceResource)
+ a.Equal(1, len(database.InstanceResource.DataSources))
+ dataSource := database.InstanceResource.DataSources[0]
+
err = ctl.changeDatabase(ctx, ctl.project, database, sheet, v1pb.Plan_ChangeDatabaseConfig_MIGRATE)
a.NoError(err)
@@ -191,11 +195,12 @@ func TestSQLExport(t *testing.T) {
checkResults(a, tt.databaseName, statement, tt.queryResult, results)
request := &v1pb.ExportRequest{
- Name: database.Name,
- Format: v1pb.ExportFormat_SQL,
- Limit: 1,
- Statement: tt.export,
- Password: tt.password,
+ Name: database.Name,
+ Format: v1pb.ExportFormat_SQL,
+ Limit: 1,
+ Statement: tt.export,
+ Password: tt.password,
+ DataSourceId: dataSource.Id,
}
export, err := ctl.sqlServiceClient.Export(ctx, request)
a.NoError(err)