<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">I should be able to return a single value from my view(that is, not a tuple) and have my value passed to my custom response class. In this case I have a response class that detects whether JSON or pickle data was requested by the client and dumps the return value appropriately. This allows me to simply return a list or dict from my view without having to detect and dump the appropriate type.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@mod.route('/')
def return_json_or_pickle():
    return ['foo', 'bar', 'bat']"><pre class="notranslate"><span class="pl-en">@<span class="pl-s1">mod</span>.<span class="pl-en">route</span>(<span class="pl-s">'/'</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">return_json_or_pickle</span>():
    <span class="pl-k">return</span> [<span class="pl-s">'foo'</span>, <span class="pl-s">'bar'</span>, <span class="pl-s">'bat'</span>]</pre></div>
<p dir="auto">As of Flask 0.12.2 this worked - make_response would pass the list to my custom response class and my client would get what it wanted.</p>
<h3 dir="auto">Actual Behavior</h3>
<p dir="auto">As of 1.0, commit <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="224177482" data-permission-text="Title is private" data-url="https://github.com/pallets/flask/issues/2256" data-hovercard-type="pull_request" data-hovercard-url="/pallets/flask/pull/2256/hovercard" href="https://github.com/pallets/flask/pull/2256">#2256</a> was merged which added an explicit check to see if the return value was a list; treating a list as a tuple return in that case. I now get a typeerror:</p>
<div class="highlight highlight-text-python-traceback notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="TypeError: The view function did not return a valid response tuple. The tuple must have the form (body, status, headers), (body, status), or (body, headers)."><pre class="notranslate"><span class="pl-en">TypeError</span>: <span class="pl-s">The view function did not return a valid response tuple. The tuple must have the form (body, status, headers), (body, status), or (body, headers).</span></pre></div>
<p dir="auto">If I change my view function to return a tuple:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@mod.route('/')
def return_json_or_pickle():
    return ['foo', 'bar', 'bat'], 200"><pre class="notranslate"><span class="pl-en">@<span class="pl-s1">mod</span>.<span class="pl-en">route</span>(<span class="pl-s">'/'</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">return_json_or_pickle</span>():
    <span class="pl-k">return</span> [<span class="pl-s">'foo'</span>, <span class="pl-s">'bar'</span>, <span class="pl-s">'bat'</span>], <span class="pl-c1">200</span></pre></div>
<p dir="auto">the previous functionality is restored! This confirms that tuple handling is of course perfectly fine. I have a <a href="https://github.com/pallets/flask/pull/2737" data-hovercard-type="pull_request" data-hovercard-url="/pallets/flask/pull/2737/hovercard">pull request</a> prepared which should do a very nice job of resolving the issue - it simply omits <code class="notranslate">list</code> from the type check in make_response. Since a list is not a valid response anyway, there's no reason I can see for it to be there.</p>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Python version: 3.6</li>
<li>Flask version: 1.0</li>
<li>Werkzeug version: n/a</li>
</ul>
<p dir="auto">I had written a simple wrapper to take all the response primitives, and jsonify them before returning to client like so:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class JSONifyResponseWrapper(Response):
    default_mimetype = 'application/json'

    @classmethod
    def force_type(cls, rv, environ=None):
        try:
            rv = jsonify(rv)
        finally:
            return super(JSONifyResponseWrapper, cls).force_type(rv, environ)"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">JSONifyResponseWrapper</span>(<span class="pl-v">Response</span>):
    <span class="pl-s1">default_mimetype</span> <span class="pl-c1">=</span> <span class="pl-s">'application/json'</span>

    <span class="pl-en">@<span class="pl-s1">classmethod</span></span>
    <span class="pl-k">def</span> <span class="pl-en">force_type</span>(<span class="pl-s1">cls</span>, <span class="pl-s1">rv</span>, <span class="pl-s1">environ</span><span class="pl-c1">=</span><span class="pl-c1">None</span>):
        <span class="pl-k">try</span>:
            <span class="pl-s1">rv</span> <span class="pl-c1">=</span> <span class="pl-en">jsonify</span>(<span class="pl-s1">rv</span>)
        <span class="pl-k">finally</span>:
            <span class="pl-k">return</span> <span class="pl-en">super</span>(<span class="pl-v">JSONifyResponseWrapper</span>, <span class="pl-s1">cls</span>).<span class="pl-en">force_type</span>(<span class="pl-s1">rv</span>, <span class="pl-s1">environ</span>)</pre></div>
<p dir="auto">Then i set app.response_class to the class above.</p>
<p dir="auto">However, in flask 1.0 , the routes are required to return a tuple.<br>
This means if I have a route like this:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@base_blueprint.route('', methods=['Post'])
def hello():
    a = {&quot;hello&quot;:&quot;world&quot;} 
   return a"><pre class="notranslate"><span class="pl-en">@<span class="pl-s1">base_blueprint</span>.<span class="pl-en">route</span>(<span class="pl-s">''</span>, <span class="pl-s1">methods</span><span class="pl-c1">=</span>[<span class="pl-s">'Post'</span>])</span>
<span class="pl-k">def</span> <span class="pl-en">hello</span>():
    <span class="pl-s1">a</span> <span class="pl-c1">=</span> {<span class="pl-s">"hello"</span>:<span class="pl-s">"world"</span>} 
   <span class="pl-k">return</span> <span class="pl-s1">a</span></pre></div>
<p dir="auto">The client receives a valid json object.</p>
<p dir="auto">But if I do this:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@base_blueprint.route('', methods=['Post'])
def hello():
    a = [i for i in range(100)]
   return a"><pre class="notranslate"><span class="pl-en">@<span class="pl-s1">base_blueprint</span>.<span class="pl-en">route</span>(<span class="pl-s">''</span>, <span class="pl-s1">methods</span><span class="pl-c1">=</span>[<span class="pl-s">'Post'</span>])</span>
<span class="pl-k">def</span> <span class="pl-en">hello</span>():
    <span class="pl-s1">a</span> <span class="pl-c1">=</span> [<span class="pl-s1">i</span> <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-c1">100</span>)]
   <span class="pl-k">return</span> <span class="pl-s1">a</span></pre></div>
<p dir="auto">Flask will throw this error:</p>
<blockquote>
<p dir="auto">TypeError: The view function did not return a valid response tuple. The tuple must have the form (body, status, headers), (body, status), or (body, headers)`</p>
</blockquote>