{"record":{"id":"bb135d51326307c7","repo":"googleapis/mcp-toolbox","slug":"failed-to-update-materialized-view-w","errorCode":null,"errorMessage":"failed to update materialized view: %w","messagePattern":"failed to update materialized view: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/bigtable/admin_wrappers.go","lineNumber":264,"sourceCode":"\tconf := &bigtable.MaterializedViewInfo{\n\t\tMaterializedViewID: materializedViewId,\n\t\tQuery:              query,\n\t}\n\terr := s.InstanceAdmin.CreateMaterializedView(ctx, instanceId, conf)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create materialized view: %w\", err)\n\t}\n\treturn map[string]string{\"status\": \"materialized view created successfully\"}, nil\n}\n\nfunc (s *Source) UpdateMaterializedView(ctx context.Context, instanceId, materializedViewId, query string) (any, error) {\n\tconf := bigtable.MaterializedViewInfo{ // MUST be value per bigtable SDK\n\t\tMaterializedViewID: materializedViewId,\n\t\tQuery:              query,\n\t}\n\terr := s.InstanceAdmin.UpdateMaterializedView(ctx, instanceId, conf)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to update materialized view: %w\", err)\n\t}\n\treturn map[string]string{\"status\": \"materialized view updated successfully\"}, nil\n}\n\nfunc (s *Source) DeleteMaterializedView(ctx context.Context, instanceId, materializedViewId string) (any, error) {\n\terr := s.InstanceAdmin.DeleteMaterializedView(ctx, instanceId, materializedViewId)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to delete materialized view: %w\", err)\n\t}\n\treturn map[string]string{\"status\": \"materialized view deleted successfully\"}, nil\n}\n","sourceCodeStart":246,"sourceCodeEnd":276,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/bigtable/admin_wrappers.go#L246-L276","documentation":"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.","triggerScenarios":"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.","commonSituations":"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'.","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"],"exampleFix":"// before: pointer config breaks SDK\nconf := &bigtable.MaterializedViewInfo{MaterializedViewID: id, Query: q}\ns.InstanceAdmin.UpdateMaterializedView(ctx, inst, *conf)\n// after: value config\nconf := bigtable.MaterializedViewInfo{MaterializedViewID: id, Query: q}\nerr := s.InstanceAdmin.UpdateMaterializedView(ctx, inst, conf)","handlingStrategy":"validation","validationCode":"views, err := src.ListMaterializedViews(ctx, instanceId)\nif err != nil { return err }\nif !containsMaterializedViewID(views, viewId) {\n    return fmt.Errorf(\"materialized view %q does not exist; create it before updating\", viewId)\n}","typeGuard":"func isNotFound(err error) bool {\n    st, ok := status.FromError(errors.Unwrap(err))\n    return ok && st.Code() == codes.NotFound\n}","tryCatchPattern":"res, err := src.UpdateMaterializedView(ctx, instanceId, viewId, query)\nif err != nil {\n    if isNotFound(err) {\n        return src.CreateMaterializedView(ctx, instanceId, viewId, query)\n    }\n    return err\n}","preventionTips":["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"],"tags":["gcp","bigtable","admin-api","permissions"],"backgroundTag":"gcp-api-error","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}