{"record":{"id":"b42231ef4b98c2ca","repo":"apache/answer","slug":"update-question-failed-w","errorCode":null,"errorMessage":"update question failed: %w","messagePattern":"update question failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/migrations/v12.go","lineNumber":75,"sourceCode":"\treturn \"question\"\n}\n\nfunc updateQuestionPostTime(ctx context.Context, x *xorm.Engine) error {\n\tquestionList := make([]QuestionPostTime, 0)\n\terr := x.Context(ctx).Find(&questionList, &entity.Question{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get questions failed: %w\", err)\n\t}\n\tfor _, item := range questionList {\n\t\tif item.PostUpdateTime.IsZero() {\n\t\t\tif !item.UpdatedAt.IsZero() {\n\t\t\t\titem.PostUpdateTime = item.UpdatedAt\n\t\t\t} else if !item.CreatedAt.IsZero() {\n\t\t\t\titem.PostUpdateTime = item.CreatedAt\n\t\t\t}\n\t\t\tif _, err = x.Context(ctx).Update(item, &QuestionPostTime{ID: item.ID}); err != nil {\n\t\t\t\tlog.Errorf(\"update %+v config failed: %s\", item, err)\n\t\t\t\treturn fmt.Errorf(\"update question failed: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":57,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/migrations/v12.go#L57-L82","documentation":"Returned by updateQuestionPostTime when updating an individual question's post_update_time column fails. The Get/find succeeded but the per-row Update() errored, aborting the migration. The driver error is wrapped with %w.","triggerScenarios":"x.Context(ctx).Update(item, &QuestionPostTime{ID: item.ID}) returns non-nil err while backfilling post_update_time for questions with zero PostUpdateTime in the v12 migration.","commonSituations":"post_update_time column missing (partial upgrade); row locked by long-running traffic; connection lost mid-migration on a large dataset.","solutions":["Inspect the wrapped driver error for the failing statement","Confirm the post_update_time column exists on the question table (run prior migrations first)","Re-run the migration; already-updated rows are skipped via the IsZero() check","Run the upgrade during low traffic to avoid lock contention"],"exampleFix":"// before\nif _, err = x.Context(ctx).Update(item, &QuestionPostTime{ID: item.ID}); err != nil {\n\tlog.Errorf(\"update %+v config failed: %s\", item, err)\n\treturn fmt.Errorf(\"update question failed: %w\", err)\n}\n// after (collect failures instead of aborting at first row)\nif _, err = x.Context(ctx).Update(item, &QuestionPostTime{ID: item.ID}); err != nil {\n\tfailedIDs = append(failedIDs, item.ID)\n\tcontinue\n}","handlingStrategy":"retry","validationCode":"// confirm the target column exists before migrating\ncols, _ := db.QueryString(\"SELECT column_name FROM information_schema.columns WHERE table_name='question'\")\n// must contain post_update_time","typeGuard":null,"tryCatchPattern":"if err := runMigrations(); err != nil {\n\tif strings.Contains(err.Error(), \"update question failed\") {\n\t\tlog.Printf(\"row update failed: %v; re-run migration, it skips fixed rows\", err)\n\t\treturn err\n\t}\n}","preventionTips":["Run migrations in order; do not skip versions","Re-run safely: rows with non-zero PostUpdateTime are skipped","Take a maintenance window to avoid row lock contention","Monitor DB connection stability on large datasets"],"tags":["database","migration","xorm","row-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-12T22:17:10.623Z"}