googleapis/mcp-toolbox · error

failed to update logical view: %w

Error message

failed to update logical view: %w

What it means

UpdateLogicalView wraps errors from InstanceAdmin.UpdateLogicalView, which replaces the SQL query of an existing logical view. Failures occur when the view does not exist (NotFound), the new query is invalid, or permissions are insufficient. The config must be passed by value per the bigtable SDK requirement.

Source

Thrown at internal/sources/bigtable/admin_wrappers.go:224

	conf := &bigtable.LogicalViewInfo{
		LogicalViewID: logicalViewId,
		Query:         query,
	}
	err := s.InstanceAdmin.CreateLogicalView(ctx, instanceId, conf)
	if err != nil {
		return nil, fmt.Errorf("failed to create logical view: %w", err)
	}
	return map[string]string{"status": "logical view created successfully"}, nil
}

func (s *Source) UpdateLogicalView(ctx context.Context, instanceId, logicalViewId, query string) (any, error) {
	conf := bigtable.LogicalViewInfo{ // MUST be value per bigtable SDK
		LogicalViewID: logicalViewId,
		Query:         query,
	}
	err := s.InstanceAdmin.UpdateLogicalView(ctx, instanceId, conf)
	if err != nil {
		return nil, fmt.Errorf("failed to update logical view: %w", err)
	}
	return map[string]string{"status": "logical view updated successfully"}, nil
}

func (s *Source) DeleteLogicalView(ctx context.Context, instanceId, logicalViewId string) (any, error) {
	err := s.InstanceAdmin.DeleteLogicalView(ctx, instanceId, logicalViewId)
	if err != nil {
		return nil, fmt.Errorf("failed to delete logical view: %w", err)
	}
	return map[string]string{"status": "logical view deleted successfully"}, nil
}

func (s *Source) GetMaterializedView(ctx context.Context, instanceId, materializedViewId string) (any, error) {
	view, err := s.InstanceAdmin.MaterializedViewInfo(ctx, instanceId, materializedViewId)
	if err != nil {
		return nil, fmt.Errorf("failed to get materialized view: %w", err)
	}
	return view, nil

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Verify the logical view exists first (ListLogicalViews/MaterializedViews or GetLogicalViewInfo) to distinguish NotFound from query errors
  2. Validate the new SQL query against current table schema
  3. Keep passing bigtable.LogicalViewInfo by value (comment in code says 'MUST be value per bigtable SDK'); a pointer can cause SDK-side failures
  4. Grant roles/bigtable.admin or bigtable.views.update to the service account

Example fix

// before: pointer config (SDK requires value)
conf := &bigtable.LogicalViewInfo{LogicalViewID: id, Query: q}
s.InstanceAdmin.UpdateLogicalView(ctx, inst, *conf)
// after: value config as SDK requires
conf := bigtable.LogicalViewInfo{LogicalViewID: id, Query: q}
err := s.InstanceAdmin.UpdateLogicalView(ctx, inst, conf)
Defensive patterns

Strategy: validation

Validate before calling

// confirm the view exists and the query parses before updating
views, err := src.ListLogicalViews(ctx, instanceId)
if err != nil { return err }
if !containsViewID(views, viewId) {
    return fmt.Errorf("logical view %q does not exist in %s; create it first", viewId, instanceId)
}

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.UpdateLogicalView(ctx, instanceId, viewId, query)
if err != nil {
    if isNotFound(err) {
        return src.CreateLogicalView(ctx, instanceId, viewId, query) // upsert pattern
    }
    return err
}

Prevention

When it happens

Trigger: Calling UpdateLogicalView (bigtable_update_logical_view tool) when: logicalViewId does not exist in instanceId, the replacement query fails validation, caller lacks bigtable.views.update permission, or a transient RPC failure occurs.

Common situations: Updating a view whose name was renamed/mispelled; SQL query drift after the underlying table schema changed; IAM role changes removed update permission; passing a pointer to LogicalViewInfo causing an SDK-level error.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/f1ddcbd4f6a98cbe. Report an issue: GitHub.