{"record":{"id":"b51ce4bff635df0e","repo":"apache/answer","slug":"update-site-info-failed-w","errorCode":null,"errorMessage":"update site info failed: %w","messagePattern":"update site info failed: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/config.go","lineNumber":88,"sourceCode":"func defaultLoginConfig(x *xorm.Engine) (err error) {\n\tfmt.Println(\"set default login config\")\n\n\tloginSiteInfo := &entity.SiteInfo{\n\t\tType: constant.SiteTypeLogin,\n\t}\n\texist, err := x.Get(loginSiteInfo)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get config failed: %w\", err)\n\t}\n\tif exist {\n\t\tvar content map[string]any\n\t\t_ = json.Unmarshal([]byte(loginSiteInfo.Content), &content)\n\t\tcontent[\"allow_password_login\"] = true\n\t\tdataByte, _ := json.Marshal(content)\n\t\tloginSiteInfo.Content = string(dataByte)\n\t\t_, err = x.ID(loginSiteInfo.ID).Cols(\"content\").Update(loginSiteInfo)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"update site info failed: %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc deactivatePlugin(x *xorm.Engine, pluginSlugName string) (err error) {\n\tfmt.Printf(\"try to deactivate plugin: %s\\n\", pluginSlugName)\n\n\titem := &entity.Config{Key: constant.PluginStatus}\n\texist, err := x.Get(item)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get config failed: %w\", err)\n\t}\n\tif !exist {\n\t\treturn nil\n\t}\n\n\tpluginStatusMapping := make(map[string]bool)","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/cli/config.go#L70-L106","documentation":"Returned by defaultLoginConfig in internal/cli/config.go when x.ID(loginSiteInfo.ID).Cols(\"content\").Update(loginSiteInfo) fails while persisting the modified allow_password_login content JSON back to the site_info table. The SELECT succeeded and the row exists, so this is a write-side failure: constraint violation, lost connection, read-only replica, or schema mismatch on the content column.","triggerScenarios":"The UPDATE statement fails due to DB connection loss between Get and Update, a read-only database/replica, a lock timeout on the site_info row held by another transaction, or the content column type/length rejecting the marshaled JSON.","commonSituations":"Concurrent admin sessions updating site settings at the same time; running the CLI against a read replica; upgrading where content column was narrowed; long-running session that hit an idle timeout before the Update executed.","solutions":["Read the wrapped driver error to identify lock timeout vs read-only vs connection loss","Confirm the database accepts writes (not a read-only replica) and re-run the command","Retry the operation — transient lock/timeout errors usually succeed on a second attempt","Check for concurrent writers to the site_info row and coordinate, and verify the content column can hold the new JSON"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// confirm DB accepts writes before updating\nvar readonly bool\nif _, err := db.SQL(\"SELECT @@read_only\").Get(&readonly); err == nil && readonly {\n    return errors.New(\"database is read-only; cannot update site info\")\n}","typeGuard":null,"tryCatchPattern":"affected, err := x.ID(loginSiteInfo.ID).Cols(\"content\").Update(loginSiteInfo)\nif err != nil {\n    if isLockTimeout(err) {\n        time.Sleep(2 * time.Second)\n        affected, err = x.ID(loginSiteInfo.ID).Cols(\"content\").Update(loginSiteInfo)\n    }\n    if err != nil {\n        return fmt.Errorf(\"update site info failed: %w\", err)\n    }\n}","preventionTips":["Retry idempotent updates to survive transient lock timeouts","Keep the DB session short between Get and Update to avoid idle timeouts","Point write operations at the primary, never a read replica","Serialize concurrent site-config updates with a lock or version column"],"tags":["go","database","xorm","update-failed"],"backgroundTag":"database-write-failed","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}