{"record":{"id":"81261dd52e52020c","repo":"apache/answer","slug":"update-config-failed-w-81261d","errorCode":null,"errorMessage":"update config failed: %w","messagePattern":"update config failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/migrations/v13.go","lineNumber":127,"sourceCode":"\t\t\tcontinue\n\t\t}\n\t\t_, err = x.Context(ctx).Insert(rel)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tdefaultConfigTable := []*entity.Config{\n\t\t{ID: 127, Key: \"rank.answer.invite_someone_to_answer\", Value: `1000`},\n\t}\n\tfor _, c := range defaultConfigTable {\n\t\texist, err := x.Context(ctx).Get(&entity.Config{ID: c.ID})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"get config failed: %w\", err)\n\t\t}\n\t\tif exist {\n\t\t\tif _, err = x.Context(ctx).Update(c, &entity.Config{ID: c.ID}); err != nil {\n\t\t\t\treturn fmt.Errorf(\"update config failed: %w\", err)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tif _, err = x.Context(ctx).Insert(&entity.Config{ID: c.ID, Key: c.Key, Value: c.Value}); err != nil {\n\t\t\treturn fmt.Errorf(\"add config failed: %w\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc updateQuestionCount(ctx context.Context, x *xorm.Engine) error {\n\t// question answer count\n\tanswers := make([]AnswerV13, 0)\n\terr := x.Context(ctx).Find(&answers, &AnswerV13{Status: entity.AnswerStatusAvailable})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get answers failed: %w\", err)\n\t}\n\tquestionAnswerCount := make(map[string]int)","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/migrations/v13.go#L109-L145","documentation":"Returned by addPrivilegeForInviteSomeoneToAnswer when the xorm Update() of the existing config ID 127 row fails. The existence check succeeded; the write of the privilege value (1000) errored. The driver error is wrapped with %w.","triggerScenarios":"x.Context(ctx).Update(c, &entity.Config{ID: c.ID}) returns non-nil err when config row 127 already exists in the v13 migration.","commonSituations":"Read-only DB user; row locked by concurrent traffic writing user ranks; schema mismatch on the config table; connection reset mid-migration.","solutions":["Inspect the wrapped driver error for the failing statement","Verify UPDATE privilege on the config table","Re-run the migration after resolving the DB issue"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify UPDATE privilege on config before migrating\nif _, err := db.Exec(\"UPDATE config SET value = value WHERE id = -1\"); err != nil {\n\treturn fmt.Errorf(\"no UPDATE privilege on config: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := runMigrations(); err != nil {\n\tif strings.Contains(err.Error(), \"update config failed\") {\n\t\tlog.Fatalf(\"config update failed, cause: %v\", errors.Unwrap(err))\n\t}\n}","preventionTips":["Grant the migration user UPDATE privileges","Stop app writes during migration to avoid row locks","Check the wrapped driver error for the exact SQL failure","Re-run the migration after fixing DB issues"],"tags":["database","migration","xorm","config-update"],"backgroundTag":"migration-db-write-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"}