Repository: deepset-ai/haystack

Issue:
Tutorial 13 fails - TranslationWrapperPipeline wrapping QuestionAnswerGenerationPipeline fails to run
**Describe the bug**
Our recent changes for batching pipeline run support have caused a bug in TranslationWrapperPipeline when a wrapped pipeline is QuestionAnswerGenerationPipeline. This particular use case is demoed in Tutorial 13. 

I have traced the bug to formatting_wrapper of the QuestionAnswerGenerationPipeline. The output format of the pipeline has been changed to support batched runs, but it seems that it has caused this issue for non-batched runs. 

**Error message**
```
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[/usr/local/lib/python3.7/dist-packages/haystack/pipelines/base.py](https://localhost:8080/#) in run(self, query, file_paths, labels, documents, meta, params, debug)
    508                     logger.debug(f"Running node `{node_id}` with input `{node_input}`")
--> 509                     node_output, stream_id = self.graph.nodes[node_id]["component"]._dispatch_run(**node_input)
    510                 except Exception as e:

6 frames
[/usr/local/lib/python3.7/dist-packages/haystack/nodes/base.py](https://localhost:8080/#) in _dispatch_run(self, **kwargs)
    200         """
--> 201         return self._dispatch_run_general(self.run, **kwargs)
    202 

[/usr/local/lib/python3.7/dist-packages/haystack/nodes/base.py](https://localhost:8080/#) in _dispatch_run_general(self, run_method, **kwargs)
    244 
--> 245         output, stream = run_method(**run_inputs, **run_params)
    246 

[/usr/local/lib/python3.7/dist-packages/haystack/nodes/translator/base.py](https://localhost:8080/#) in run(self, results, query, documents, answers, dict_key)
     62             _dict_key = dict_key or "text"
---> 63             translation_results["documents"] = self.translate(documents=documents, dict_key=_dict_key)  # type: ignore
     64 

[/usr/local/lib/python3.7/dist-packages/haystack/nodes/translator/transformers.py](https://localhost:8080/#) in translate(self, results, query, documents, dict_key)
    115             else:
--> 116                 if not isinstance(documents[0].get(dict_key, None), str):  # type: ignore
    117                     raise AttributeError(f"Dictionary should have {dict_key} key and it's value should be `str` type")

AttributeError: 'list' object has no attribute 'get'
```

**Expected behavior**
The tutorial should finish without errors


**To Reproduce**
Run Tutorial 13




Discussion:

Resolving patch:
diff --git a/haystack/nodes/translator/base.py b/haystack/nodes/translator/base.py
--- a/haystack/nodes/translator/base.py
+++ b/haystack/nodes/translator/base.py
@@ -32,7 +32,7 @@ def translate_batch(
         queries: Optional[List[str]] = None,
         documents: Optional[Union[List[Document], List[Answer], List[List[Document]], List[List[Answer]]]] = None,
         batch_size: Optional[int] = None,
-    ) -> Union[str, List[str], List[Document], List[Answer], List[List[Document]], List[List[Answer]]]:
+    ) -> List[Union[str, List[Document], List[Answer], List[str], List[Dict[str, Any]]]]:
         pass
 
     def run(  # type: ignore
diff --git a/haystack/nodes/translator/transformers.py b/haystack/nodes/translator/transformers.py
--- a/haystack/nodes/translator/transformers.py
+++ b/haystack/nodes/translator/transformers.py
@@ -161,7 +161,7 @@ def translate_batch(
         queries: Optional[List[str]] = None,
         documents: Optional[Union[List[Document], List[Answer], List[List[Document]], List[List[Answer]]]] = None,
         batch_size: Optional[int] = None,
-    ) -> Union[str, List[str], List[Document], List[Answer], List[List[Document]], List[List[Answer]]]:
+    ) -> List[Union[str, List[Document], List[Answer], List[str], List[Dict[str, Any]]]]:
         """
         Run the actual translation. You can supply a single query, a list of queries or a list (of lists) of documents.
 
@@ -181,7 +181,7 @@ def translate_batch(
         if queries:
             translated = []
             for query in tqdm(queries, disable=not self.progress_bar, desc="Translating"):
-                cur_translation = self.run(query=query)
+                cur_translation = self.translate(query=query)
                 translated.append(cur_translation)
 
         # Translate docs / answers
diff --git a/haystack/pipelines/standard_pipelines.py b/haystack/pipelines/standard_pipelines.py
--- a/haystack/pipelines/standard_pipelines.py
+++ b/haystack/pipelines/standard_pipelines.py
@@ -523,6 +523,11 @@ def __init__(
 
         self.pipeline = Pipeline()
         self.pipeline.add_node(component=input_translator, name="InputTranslator", inputs=["Query"])
+        # Make use of run_batch instead of run for output_translator if pipeline is a QuestionAnswerGenerationPipeline,
+        # as the reader's run method is overwritten by its run_batch method, which is incompatible with the translator's
+        # run method.
+        if isinstance(pipeline, QuestionAnswerGenerationPipeline):
+            setattr(output_translator, "run", output_translator.run_batch)
 
         graph = pipeline.pipeline.graph
         previous_node_name = ["InputTranslator"]


Test patch: