Repository: tartiflette/tartiflette (python)

Issue:
The `error_coercer` filled in at engine initialization isn't taken into account
While `error_coercer` parameter from the `create_engine` utility function or `cook` method from `Engine` class is properly taken into account, the `error_coercer` from the `__init__` method of the `Engine` class isn't.

* **Tartiflette version:** 1.0.0
* **Python version:** 3.7
* **Executed in docker:** No

Pull request:
Take into account the `error_coercer` parameter at `Engine` initialization
Closes #309.

Patch:
diff --git a/changelogs/next.md b/changelogs/next.md
index 76cbc00..762324d 100644
--- a/changelogs/next.md
+++ b/changelogs/next.md
@@ -7,3 +7,4 @@
 ## Fixed
 
 - Replace `and` operator for `or` operator in the `Mutation.updateRecipe` tutorial resolver condition - [ISSUE-298](https://github.com/tartiflette/tartiflette/issues/298) thrown by @helio-correia
+- Take into account the value filled in into the `error_coercer` parameter at `Engine` initialization - [ISSUE-309](https://github.com/tartiflette/tartiflette/issues/309)
diff --git a/tartiflette/engine.py b/tartiflette/engine.py
index 115e36c..56146f6 100644
--- a/tartiflette/engine.py
+++ b/tartiflette/engine.py
@@ -250,10 +250,7 @@ class Engine:
             schema_name, custom_default_resolver, custom_default_type_resolver
         )
         self._build_response = partial(
-            build_response,
-            error_coercer=error_coercer_factory(
-                error_coercer or default_error_coercer
-            ),
+            build_response, error_coercer=self._error_coercer
         )
 
         self._cooked = True


Test patch:
diff --git a/tests/functional/regressions/test_issue309.py b/tests/functional/regressions/test_issue309.py
new file mode 100644
index 0000000..e4e215f
--- /dev/null
+++ b/tests/functional/regressions/test_issue309.py
@@ -0,0 +1,57 @@
+import pytest
+
+from tartiflette import Engine, Resolver, create_engine
+
+_SDL = """
+type Query {
+  name: String
+}
+"""
+
+_QUERY = """
+query {
+  name
+}
+"""
+
+_EXPECTED = {"data": {"name": None}, "errors": [{"message": "Oopsie"}]}
+
+
+async def custom_error_coercer(exception, error):
+    return {"message": "Oopsie"}
+
+
+async def from_create_engine(schema_name):
+    return await create_engine(
+        _SDL, schema_name=schema_name, error_coercer=custom_error_coercer
+    )
+
+
+async def from_engine_class_init(schema_name):
+    engine = Engine(
+        _SDL, schema_name=schema_name, error_coercer=custom_error_coercer
+    )
+    await engine.cook()
+    return engine
+
+
+async def from_engine_class_cook(schema_name):
+    engine = Engine()
+    await engine.cook(
+        _SDL, schema_name=schema_name, error_coercer=custom_error_coercer
+    )
+    return engine
+
+
+@pytest.mark.asyncio
+@pytest.mark.parametrize(
+    "engine_factory",
+    [from_create_engine, from_engine_class_init, from_engine_class_cook],
+)
+async def test_error_coercers(random_schema_name, engine_factory):
+    @Resolver("Query.name", schema_name=random_schema_name)
+    async def resolve_query_name(*_):
+        raise Exception("Oopsie")
+
+    engine = await engine_factory(random_schema_name)
+    assert await engine.execute(_QUERY) == _EXPECTED