googleapis/mcp-toolbox · error
failed to update materialized view: %w
Error message
failed to update materialized view: %w
What it means
UpdateMaterializedView wraps errors from InstanceAdmin.UpdateMaterializedView, replacing the query of an existing materialized view. Failures occur when the view does not exist (NotFound), the new query is invalid, permissions are missing, or transient RPC errors occur. The config must be a bigtable.MaterializedViewInfo value per the SDK.
Source
Thrown at internal/sources/bigtable/admin_wrappers.go:264
conf := &bigtable.MaterializedViewInfo{
MaterializedViewID: materializedViewId,
Query: query,
}
err := s.InstanceAdmin.CreateMaterializedView(ctx, instanceId, conf)
if err != nil {
return nil, fmt.Errorf("failed to create materialized view: %w", err)
}
return map[string]string{"status": "materialized view created successfully"}, nil
}
func (s *Source) UpdateMaterializedView(ctx context.Context, instanceId, materializedViewId, query string) (any, error) {
conf := bigtable.MaterializedViewInfo{ // MUST be value per bigtable SDK
MaterializedViewID: materializedViewId,
Query: query,
}
err := s.InstanceAdmin.UpdateMaterializedView(ctx, instanceId, conf)
if err != nil {
return nil, fmt.Errorf("failed to update materialized view: %w", err)
}
return map[string]string{"status": "materialized view updated successfully"}, nil
}
func (s *Source) DeleteMaterializedView(ctx context.Context, instanceId, materializedViewId string) (any, error) {
err := s.InstanceAdmin.DeleteMaterializedView(ctx, instanceId, materializedViewId)
if err != nil {
return nil, fmt.Errorf("failed to delete materialized view: %w", err)
}
return map[string]string{"status": "materialized view deleted successfully"}, nil
}
View on GitHub (pinned to 8cc6e09de2)
Solutions
- Verify the materialized view exists (GetMaterializedView) before updating to distinguish NotFound from query errors
- Validate the new query against current schema
- Pass bigtable.MaterializedViewInfo by value, matching the SDK requirement noted in the source
- Grant roles/bigtable.admin or the materialized-view update permission
Example fix
// before: pointer config breaks SDK
conf := &bigtable.MaterializedViewInfo{MaterializedViewID: id, Query: q}
s.InstanceAdmin.UpdateMaterializedView(ctx, inst, *conf)
// after: value config
conf := bigtable.MaterializedViewInfo{MaterializedViewID: id, Query: q}
err := s.InstanceAdmin.UpdateMaterializedView(ctx, inst, conf) Defensive patterns
Strategy: validation
Validate before calling
views, err := src.ListMaterializedViews(ctx, instanceId)
if err != nil { return err }
if !containsMaterializedViewID(views, viewId) {
return fmt.Errorf("materialized view %q does not exist; create it before updating", viewId)
} Type guard
func isNotFound(err error) bool {
st, ok := status.FromError(errors.Unwrap(err))
return ok && st.Code() == codes.NotFound
} Try / catch
res, err := src.UpdateMaterializedView(ctx, instanceId, viewId, query)
if err != nil {
if isNotFound(err) {
return src.CreateMaterializedView(ctx, instanceId, viewId, query)
}
return err
} Prevention
- Prefer upsert: update first, create on NotFound
- Pass bigtable.MaterializedViewInfo by value — the SDK rejects pointer configs
- Re-validate the query after any underlying table schema change
- Keep materialized-view update IAM permissions on the service account
When it happens
Trigger: Calling UpdateMaterializedView (bigtable_update_materialized_view tool) when: materializedViewId does not exist, the replacement query fails validation, caller lacks update permission, or a pointer (instead of a value) is passed to the SDK causing a client-side error.
Common situations: Updating a view dropped elsewhere; query drift after schema changes; IAM changes; violating the SDK's value-type requirement documented in the code comment 'MUST be value per bigtable SDK'.
Related errors
- failed to list materialized views: %w
- failed to create logical view: %w
- failed to update logical view: %w
- failed to delete logical view: %w
- failed to get materialized view: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/bb135d51326307c7.
Report an issue: GitHub.