{"record":{"id":"1fef648796951e62","repo":"apache/answer","slug":"get-tag-rel-failed-w","errorCode":null,"errorMessage":"get tag rel failed: %w","messagePattern":"get tag rel failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/migrations/v13.go","lineNumber":178,"sourceCode":"\t\t_, ok := questionAnswerCount[item.ID]\n\t\tif ok {\n\t\t\titem.AnswerCount = questionAnswerCount[item.ID]\n\t\t\tif _, err = x.Context(ctx).Cols(\"answer_count\").Update(item, &QuestionV13{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\n// updateTagCount update tag count\nfunc updateTagCount(ctx context.Context, x *xorm.Engine) error {\n\ttagRelList := make([]entity.TagRel, 0)\n\terr := x.Context(ctx).Find(&tagRelList, &entity.TagRel{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get tag rel failed: %w\", err)\n\t}\n\tquestionIDs := make([]string, 0)\n\tquestionsAvailableMap := make(map[string]bool)\n\tquestionsHideMap := make(map[string]bool)\n\tfor _, item := range tagRelList {\n\t\tquestionIDs = append(questionIDs, item.ObjectID)\n\t\tquestionsAvailableMap[item.ObjectID] = false\n\t\tquestionsHideMap[item.ObjectID] = false\n\t}\n\tquestionList := make([]QuestionV13, 0)\n\terr = x.Context(ctx).In(\"id\", questionIDs).And(builder.Lt{\"question.status\": entity.QuestionStatusDeleted}).Find(&questionList, &QuestionV13{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get questions failed: %w\", err)\n\t}\n\tfor _, question := range questionList {\n\t\t_, ok := questionsAvailableMap[question.ID]\n\t\tif ok {\n\t\t\tquestionsAvailableMap[question.ID] = true","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/migrations/v13.go#L160-L196","documentation":"Wraps an xorm Find error while loading all tag relations (entity.TagRel) at the start of updateTagCount, which recomputes tag question counts. If the tag_rel table cannot be read, the migration step aborts with this wrapped error.","triggerScenarios":"x.Context(ctx).Find(&tagRelList, &entity.TagRel{}) failing due to missing tag_rel table, connection loss, schema drift between entity.TagRel and the table, or cancelled context.","commonSituations":"Databases upgraded manually where tag_rel schema lags the code; connection pool exhausted during long migration runs; read replicas lagging or unavailable.","solutions":["Read the wrapped cause to identify the driver error","Verify tag_rel table exists and matches entity.TagRel fields","Re-run the migration after restoring connectivity","Run against the primary DB, not a read replica, for migrations"],"exampleFix":"// before\nerr := x.Context(ctx).Find(&tagRelList, &entity.TagRel{})\n// after\nif err := x.Context(ctx).Find(&tagRelList, &entity.TagRel{}); err != nil {\n    return fmt.Errorf(\"get tag rel failed: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"if exists, _ := x.IsTableExist(&entity.TagRel{}); !exists {\n    return fmt.Errorf(\"tag_rel table missing; run prior migrations first\")\n}","typeGuard":null,"tryCatchPattern":"if err := updateTagCount(ctx, engine); err != nil {\n    log.Errorf(\"tag count migration failed: %v\", err)\n    return err\n}","preventionTips":["Verify table existence before data-migration steps","Run migrations with a dedicated DB user having sufficient grants","Avoid read replicas for migration reads","Monitor connection health during long migrations"],"tags":["database","xorm","migration"],"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"}