From 7383e9115acff68248e68d4b122b9158f585c4b1 Mon Sep 17 00:00:00 2001 From: Hari Date: Fri, 22 Mar 2024 00:03:57 +0530 Subject: [PATCH] fix: when using --qa-enable and --qa-disable the answers to disabled questions were not being added to the generated config file (#1163) Signed-off-by: Harikrishnan Balagopal --- qaengine/engine.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/qaengine/engine.go b/qaengine/engine.go index f1bbc0a4..61031cec 100644 --- a/qaengine/engine.go +++ b/qaengine/engine.go @@ -140,16 +140,25 @@ func FetchAnswer(prob qatypes.Problem) (qatypes.Problem, error) { logrus.Debugf("Problem already solved.") return prob, nil } - if isQuestionDisabled(prob) { - return defaultEngine.FetchAnswer(prob) - } var err error logrus.Debug("looping through the engines to try and fetch the answer") + isDisabled := isQuestionDisabled(prob) for _, engine := range engines { logrus.Debugf("engine '%T'", engine) if prob.Desc == "" && engine.IsInteractiveEngine() { return defaultEngine.FetchAnswer(prob) } + if isDisabled && engine.IsInteractiveEngine() { + logrus.Debugf("The question belongs to a disabled category so we won't ask the user for the answer") + prob, err = defaultEngine.FetchAnswer(prob) + if err != nil { + return prob, err + } + if prob.Answer != nil { + prob = changeSelectToInputForOther(prob) + } + break + } prob, err = engine.FetchAnswer(prob) if err != nil { if _, ok := err.(*qatypes.ValidationError); ok { @@ -175,6 +184,13 @@ func FetchAnswer(prob qatypes.Problem) (qatypes.Problem, error) { logrus.Debug("there is no interactive engine") return prob, fmt.Errorf("failed to fetch the answer for problem: %+v . Error: %w", prob, err) } + if isDisabled { + logrus.Debugf("the question is from a disabled category so try with default engine") + prob, err = defaultEngine.FetchAnswer(prob) + if err != nil || prob.Answer == nil { + return prob, fmt.Errorf("failed to fetch the answer for problem: %+v . Error: %w", prob, err) + } + } for err != nil || prob.Answer == nil { prob, err = lastEngine.FetchAnswer(prob) if err != nil {