Fix nil pointer panic in workspace table Update and Delete methods (#10590)

When StatementBegin encounters an error (e.g., table not found in staging
root), it stores the error in wtu.err but leaves tableWriter as nil. The
Update and Delete methods were dereferencing tableWriter before checking
if it was nil, causing a panic.

This fix adds an early return to check for errors from StatementBegin
before attempting to use tableWriter, preventing the nil pointer
dereference.
This commit is contained in:
nullun
2026-03-02 21:38:37 +00:00
committed by GitHub
parent 7a8b2dfc8f
commit 1912c5a08d

View File

@@ -147,6 +147,10 @@ func (wtm *WorkspaceTableModifier) statementComplete(ctx *sql.Context) error {
}
func (wtu *WorkspaceTableUpdater) Update(ctx *sql.Context, old sql.Row, new sql.Row) error {
if wtu.err != nil {
return *wtu.err
}
if old == nil || new == nil {
return fmt.Errorf("Runtime error: expected non-nil inputs to WorkspaceTableUpdater.Update")
}
@@ -209,6 +213,10 @@ func (wtd *WorkspaceTableDeleter) StatementBegin(ctx *sql.Context) {
}
func (wtd *WorkspaceTableDeleter) Delete(c *sql.Context, row sql.Row) error {
if wtd.err != nil {
return *wtd.err
}
if !wtd.modifiable {
return errors.New(fmt.Sprintf("%s table is not modifiable due to schema change", wtd.workspaceTableName))
}