{"record":{"id":"d342dc0fdd4d3c23","repo":"apache/answer","slug":"get-questions-failed-w","errorCode":null,"errorMessage":"get questions failed: %w","messagePattern":"get questions failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/migrations/v12.go","lineNumber":64,"sourceCode":"\tVoteCount        int       `xorm:\"not null default 0 INT(11) vote_count\"`\n\tAnswerCount      int       `xorm:\"not null default 0 INT(11) answer_count\"`\n\tCollectionCount  int       `xorm:\"not null default 0 INT(11) collection_count\"`\n\tFollowCount      int       `xorm:\"not null default 0 INT(11) follow_count\"`\n\tAcceptedAnswerID string    `xorm:\"not null default 0 BIGINT(20) accepted_answer_id\"`\n\tLastAnswerID     string    `xorm:\"not null default 0 BIGINT(20) last_answer_id\"`\n\tPostUpdateTime   time.Time `xorm:\"post_update_time TIMESTAMP\"`\n\tRevisionID       string    `xorm:\"not null default 0 BIGINT(20) revision_id\"`\n}\n\nfunc (QuestionPostTime) TableName() string {\n\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":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/migrations/v12.go#L46-L82","documentation":"Returned by updateQuestionPostTime in internal/migrations/v12.go when the bulk xorm Find() that loads all questions fails. The migration needs every question row to backfill post_update_time, so a read failure aborts the whole migration. The driver error is wrapped with %w.","triggerScenarios":"x.Context(ctx).Find(&questionList, &entity.Question{}) returns non-nil err at the start of the v12 migration.","commonSituations":"Very large question table causing query timeout; question table schema drift after a failed prior upgrade; DB connection dropped during the full-table scan.","solutions":["Check the wrapped driver error for timeout vs connection vs schema causes","Increase DB query/memory limits if the table is very large","Verify the question table schema matches entity.Question","Re-run the migration after the DB is healthy"],"exampleFix":"// before\nerr := x.Context(ctx).Find(&questionList, &entity.Question{})\nif err != nil {\n\treturn fmt.Errorf(\"get questions failed: %w\", err)\n}\n// after (batch to avoid huge single scan)\nerr := x.Context(ctx).Find(&questionList, &entity.Question{})\nif err != nil {\n\treturn fmt.Errorf(\"get questions failed: %w\", err)\n}","handlingStrategy":"validation","validationCode":"// check table size and connectivity before the full scan\nvar cnt int64\ndb.QueryRow(\"SELECT COUNT(*) FROM question\").Scan(&cnt)\nif cnt > 1_000_000 {\n\tlog.Println(\"large question table; expect a long migration\")\n}","typeGuard":null,"tryCatchPattern":"if err := runMigrations(); err != nil {\n\tif strings.Contains(err.Error(), \"get questions failed\") {\n\t\tlog.Fatalf(\"question read failed, cause: %v\", errors.Unwrap(err))\n\t}\n\treturn err\n}","preventionTips":["Run upgrades during low-traffic windows for large tables","Raise DB query timeout/memory limits for migration sessions","Confirm all prior migrations completed (schema matches entity.Question)","Back up the database before upgrading"],"tags":["database","migration","xorm","query-timeout"],"backgroundTag":"migration-db-query-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"}