{"record":{"id":"83a2a01c03327fe2","repo":"apache/answer","slug":"update-site-info-failed-w-83a2a0","errorCode":null,"errorMessage":"update site info failed: %w","messagePattern":"update site info failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/migrations/v10.go","lineNumber":51,"sourceCode":"\nfunc addLoginLimitations(ctx context.Context, x *xorm.Engine) error {\n\tloginSiteInfo := &entity.SiteInfo{\n\t\tType: constant.SiteTypeLogin,\n\t}\n\texist, err := x.Context(ctx).Get(loginSiteInfo)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get config failed: %w\", err)\n\t}\n\tif exist {\n\t\tcontent := &schema.SiteLoginReq{}\n\t\t_ = json.Unmarshal([]byte(loginSiteInfo.Content), content)\n\t\tcontent.AllowEmailRegistrations = true\n\t\tcontent.AllowEmailDomains = make([]string, 0)\n\t\tdata, _ := json.Marshal(content)\n\t\tloginSiteInfo.Content = string(data)\n\t\t_, err = x.Context(ctx).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\n\tinterfaceSiteInfo := &entity.SiteInfo{\n\t\tType: constant.SiteTypeInterface,\n\t}\n\texist, err = x.Context(ctx).Get(interfaceSiteInfo)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get config failed: %w\", err)\n\t}\n\tsiteUsers := &schema.SiteUsersReq{\n\t\tAllowUpdateDisplayName: true,\n\t\tAllowUpdateUsername:    true,\n\t\tAllowUpdateAvatar:      true,\n\t\tAllowUpdateBio:         true,\n\t\tAllowUpdateWebsite:     true,\n\t\tAllowUpdateLocation:    true,\n\t}","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/migrations/v10.go#L33-L69","documentation":"addLoginLimitations rewrites the login site_info content JSON (enabling email registrations, clearing domain list) and updates only the 'content' column. If the UPDATE fails, it returns 'update site info failed: %w'.","triggerScenarios":"x.Context(ctx).ID(loginSiteInfo.ID).Cols(\"content\").Update(loginSiteInfo) errors: write permission denied, row deleted concurrently (ID no longer matches), connection drop, or row locked by another transaction.","commonSituations":"Migration user lacks UPDATE privilege on site_info; admin deleted/edited the login config while migration runs; DB in read-only maintenance mode.","solutions":["Verify UPDATE privilege on site_info for the migration user","Check the wrapped DB error for lock/timeout/deadlock details","Ensure migrations run during a maintenance window with no concurrent config edits","Re-run the migration after resolving the write failure"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify UPDATE rights before the migration attempts writes\nif _, err := engine.Exec(\"SELECT 1 FROM site_info LIMIT 1 FOR UPDATE\"); err != nil {\n    return fmt.Errorf(\"site_info not writable/lockable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := migrations.Migrate(db); err != nil {\n    if strings.Contains(err.Error(), \"update site info failed\") {\n        log.Errorf(\"failed updating login site config (check privileges/locks): %v\", err)\n    }\n    return err\n}","preventionTips":["Grant UPDATE privilege on site_info to the migration user","Run migrations in a maintenance window without concurrent admin edits","Backup site_info content before update migrations","Check for row locks/deadlocks in DB logs on failure"],"tags":["database","migration","update-failed","site-config"],"backgroundTag":"migration-config-update-failed","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}