Skip to content

Commit 81699a3

Browse files
authored
fix(oracle): update oracle-execute-sql tool interface to match source signature (#2627)
## Description This PR fixes a critical signature mismatch that caused all `oracle-execute-sql` tool invocations to fail with an incompatible source type error (`500` Internal Server Error). In a previous PR (#2323), the `RunSQL` method in the Oracle Source was updated to include a `readOnly` bool parameter to support DML operations for the `oracle-sql` tool: However, the `oracle-execute-sql` tool's required interface (`compatibleSource`) was inadvertently left unchanged, still expecting the old 3-argument signature. Because Go interfaces are satisfied implicitly, the updated Oracle source no longer implemented the `oracle-execute-sql` tool's interface, causing `tools.GetCompatibleSource` to reject it at runtime during invocation. 🛠️ Fixes #2614
1 parent a182b05 commit 81699a3

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

internal/tools/oracle/oracleexecutesql/oracleexecutesql.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (tools.T
3434

3535
type compatibleSource interface {
3636
OracleDB() *sql.DB
37-
RunSQL(context.Context, string, []any) (any, error)
37+
RunSQL(context.Context, string, []any, bool) (any, error)
3838
}
3939

4040
type Config struct {
4141
Name string `yaml:"name" validate:"required"`
4242
Type string `yaml:"type" validate:"required"`
4343
Source string `yaml:"source" validate:"required"`
4444
Description string `yaml:"description" validate:"required"`
45+
ReadOnly *bool `yaml:"readOnly"`
4546
AuthRequired []string `yaml:"authRequired"`
4647
}
4748

@@ -96,7 +97,13 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
9697
return nil, util.NewClientServerError("error getting logger", http.StatusInternalServerError, err)
9798
}
9899
logger.DebugContext(ctx, "executing `%s` tool query: %s", resourceType, sqlParam)
99-
resp, err := source.RunSQL(ctx, sqlParam, nil)
100+
101+
isReadOnly := true
102+
if t.ReadOnly != nil {
103+
isReadOnly = *t.ReadOnly
104+
}
105+
106+
resp, err := source.RunSQL(ctx, sqlParam, nil, isReadOnly)
100107
if err != nil {
101108
return nil, util.ProcessGeneralError(err)
102109
}

internal/tools/oracle/oracleexecutesql/oracleexecutesql_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ func TestParseFromYamlOracleExecuteSql(t *testing.T) {
1616
if err != nil {
1717
t.Fatalf("unexpected error: %s", err)
1818
}
19+
20+
valTrue := true
21+
valFalse := false
1922
tcs := []struct {
2023
desc string
2124
in string
@@ -61,6 +64,48 @@ func TestParseFromYamlOracleExecuteSql(t *testing.T) {
6164
},
6265
},
6366
},
67+
{
68+
desc: "example with explicit readOnly true",
69+
in: `
70+
kind: tools
71+
name: safe_query
72+
type: oracle-execute-sql
73+
source: db-prod
74+
description: Safe read operation.
75+
readOnly: true
76+
`,
77+
want: server.ToolConfigs{
78+
"safe_query": oracleexecutesql.Config{
79+
Name: "safe_query",
80+
Type: "oracle-execute-sql",
81+
Source: "db-prod",
82+
Description: "Safe read operation.",
83+
ReadOnly: &valTrue,
84+
AuthRequired: []string{},
85+
},
86+
},
87+
},
88+
{
89+
desc: "example with explicit readOnly false (DML)",
90+
in: `
91+
kind: tools
92+
name: update_user
93+
type: oracle-execute-sql
94+
source: db-prod
95+
description: Updates user table.
96+
readOnly: false
97+
`,
98+
want: server.ToolConfigs{
99+
"update_user": oracleexecutesql.Config{
100+
Name: "update_user",
101+
Type: "oracle-execute-sql",
102+
Source: "db-prod",
103+
Description: "Updates user table.",
104+
ReadOnly: &valFalse,
105+
AuthRequired: []string{},
106+
},
107+
},
108+
},
64109
}
65110
for _, tc := range tcs {
66111
t.Run(tc.desc, func(t *testing.T) {

0 commit comments

Comments
 (0)