Repository: falconry/falcon
Pull request #1277 (2018-05-13 05:56:59)

Set mid default to API.__init__ to True for independent_middleware kwarg
#1276 

KingAkeem: @kgriffs I fixed the failing tests :)
codecov[bot]: # [Codecov](https://codecov.io/gh/falconry/falcon/pull/1277?src=pr&el=h1) Report
> Merging [#1277](https://codecov.io/gh/falconry/falcon/pull/1277?src=pr&el=desc) into [master](https://codecov.io/gh/falconry/falcon/commit/25613d41ec12fd7baf0b6a5a7648b023cc4b49df?src=pr&el=desc) will **decrease** coverage by `0.11%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/falconry/falcon/pull/1277/graphs/tree.svg?src=pr&token=zOtkfNQ3h6&width=650&height=150)](https://codecov.io/gh/falconry/falcon/pull/1277?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1277      +/-   ##
==========================================
- Coverage     100%   99.88%   -0.12%     
==========================================
  Files          38       38              
  Lines        2516     2516              
  Branches      385      385              
==========================================
- Hits         2516     2513       -3     
- Misses          0        2       +2     
- Partials        0        1       +1
```


| [Impacted Files](https://codecov.io/gh/falconry/falcon/pull/1277?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [falcon/api\_helpers.py](https://codecov.io/gh/falconry/falcon/pull/1277/diff?src=pr&el=tree#diff-ZmFsY29uL2FwaV9oZWxwZXJzLnB5) | `96.34% <0%> (-3.66%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/falconry/falcon/pull/1277?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/falconry/falcon/pull/1277?src=pr&el=footer). Last update [25613d4...668e849](https://codecov.io/gh/falconry/falcon/pull/1277?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/falcon/api.py b/falcon/api.py
index 7fdd650..f006028 100644
--- a/falcon/api.py
+++ b/falcon/api.py
@@ -108,10 +108,13 @@ class API(object):
             to use in lieu of the default engine.
             (See also: :ref:`Custom Routers <routing_custom>`)
 
-        independent_middleware (bool): Set to ``True`` if response
-            middleware should be executed independently of whether or
+        independent_middleware (bool): Set to ``False`` if response
+            middleware should not be executed independently of whether or
             not request middleware raises an exception (default
-            ``False``).
+            ``True``). When this option is set to ``False``, a middleware
+            component's ``process_response()`` method will NOT be called
+            when that same component's ``process_request()`` (or that of
+            a component higher up in the stack) raises an exception.
 
     Attributes:
         req_options: A set of behavioral options related to incoming
@@ -146,7 +149,7 @@ class API(object):
     def __init__(self, media_type=DEFAULT_MEDIA_TYPE,
                  request_type=Request, response_type=Response,
                  middleware=None, router=None,
-                 independent_middleware=False):
+                 independent_middleware=True):
         self._sinks = []
         self._media_type = media_type
         self._static_routes = []


Test patch:
diff --git a/tests/test_middleware.py b/tests/test_middleware.py
index 46dad6d..8a718d2 100644
--- a/tests/test_middleware.py
+++ b/tests/test_middleware.py
@@ -404,7 +404,7 @@ class TestSeveralMiddlewares(TestMiddleware):
         assert 'transaction_id' in context
         assert 'start_time' not in context
         assert 'mid_time' not in context
-        assert 'end_time' not in context
+        assert 'end_time' in context
         assert 'error_handler' in context
 
     def test_order_mw_executed_when_exception_in_resp(self):
@@ -502,6 +502,7 @@ class TestSeveralMiddlewares(TestMiddleware):
         # Any mw is executed now...
         expectedExecutedMethods = [
             'ExecutedFirstMiddleware.process_request',
+            'ExecutedLastMiddleware.process_response',
             'ExecutedFirstMiddleware.process_response'
         ]
         assert expectedExecutedMethods == context['executed_methods']