Files
responder/migration-v6.html
2026-07-14 04:14:56 +00:00

207 lines
13 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="en" data-content_root="./">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Migrating to Responder 6.0 &#8212; responder 9.2.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=5ecbeea2" />
<link rel="stylesheet" type="text/css" href="_static/basic.css?v=b08954a9" />
<link rel="stylesheet" type="text/css" href="_static/alabaster.css?v=eb4102c5" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css?v=76b2166b" />
<link rel="stylesheet" type="text/css" href="_static/sphinx-design.min.css?v=95c83b7e" />
<link rel="stylesheet" type="text/css" href="_static/design-elements.e5416f61bae5d36adc6d722a2b6f8cff.css?v=452a8e97" />
<script src="_static/documentation_options.js?v=e8b940be"></script>
<script src="_static/doctools.js?v=fd6eb6e6"></script>
<script src="_static/sphinx_highlight.js?v=6ffebe34"></script>
<script src="_static/clipboard.min.js?v=a7894cd8"></script>
<script src="_static/copybutton.js?v=fd10adb8"></script>
<script>
</script>
<script src="_static/design-tabs.js?v=f930bc37"></script>
<script src="_static/design-elements.bbdccc18c4abea9397628f9fea3d48c2.js?v=03c7770e"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Migrating to Responder 5.0" href="migration-v5.html" />
<link rel="prev" title="Migrating to v7" href="migration-v7.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
</head><body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="migrating-to-responder-6-0">
<h1>Migrating to Responder 6.0<a class="headerlink" href="#migrating-to-responder-6-0" title="Link to this heading"></a></h1>
<p>Responder 6.0 is a small, deliberate major release. It adds <strong>no new features</strong>:
it removes the deprecation shims introduced during 5.x and flips a handful of
defaults to the more-correct behavior. The <code class="docutils literal notranslate"><span class="pre">(req,</span> <span class="pre">resp)</span></code> core, dependency
injection, typed I/O, auth, and uploads are all unchanged.</p>
<p>Every change below was announced with a <code class="docutils literal notranslate"><span class="pre">DeprecationWarning</span></code> (or an opt-in knob)
in a 5.x release, so you can fix your code on 5.x first and upgrade to 6.0 with
no surprises. Run your test suite with <code class="docutils literal notranslate"><span class="pre">-W</span> <span class="pre">error::DeprecationWarning</span></code> to surface
everything that needs attention.</p>
<section id="deprecation-policy">
<h2>Deprecation policy<a class="headerlink" href="#deprecation-policy" title="Link to this heading"></a></h2>
<p>A behavior that changes in a major release is first deprecated in a minor: it
keeps working but emits a <code class="docutils literal notranslate"><span class="pre">DeprecationWarning</span></code> (or is gated behind an opt-in
flag) for at least one minor-release cycle before the major flips it.</p>
</section>
<section id="breaking-changes">
<h2>Breaking changes<a class="headerlink" href="#breaking-changes" title="Link to this heading"></a></h2>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Change</p></th>
<th class="head"><p>Staged in</p></th>
<th class="head"><p>What to do</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">req.method</span></code> returns a plain uppercase <code class="docutils literal notranslate"><span class="pre">str</span></code> (the case-insensitive <code class="docutils literal notranslate"><span class="pre">HTTPMethod</span></code> shim is removed)</p></td>
<td><p>5.0</p></td>
<td><p>Compare against uppercase literals: <code class="docutils literal notranslate"><span class="pre">req.method</span> <span class="pre">==</span> <span class="pre">&quot;GET&quot;</span></code>.</p></td>
</tr>
<tr class="row-odd"><td><p>Dependency providers must name their request parameter <code class="docutils literal notranslate"><span class="pre">req</span></code>/<code class="docutils literal notranslate"><span class="pre">request</span></code> (or annotate it <code class="docutils literal notranslate"><span class="pre">Request</span></code>); the single-unnamed-parameter shim is removed</p></td>
<td><p>5.0</p></td>
<td><p>Rename the parameter, or annotate it <code class="docutils literal notranslate"><span class="pre">Request</span></code>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">await</span> <span class="pre">req.media(&quot;files&quot;)</span></code> returns streaming <code class="docutils literal notranslate"><span class="pre">UploadFile</span></code> objects instead of a fully-buffered bytes-dict</p></td>
<td><p>5.6</p></td>
<td><p>Use <code class="docutils literal notranslate"><span class="pre">File()</span></code> markers (<code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">def</span> <span class="pre">h(req,</span> <span class="pre">resp,</span> <span class="pre">*,</span> <span class="pre">f:</span> <span class="pre">UploadFile</span> <span class="pre">=</span> <span class="pre">File(...))</span></code>), or read <code class="docutils literal notranslate"><span class="pre">.filename</span></code> / <code class="docutils literal notranslate"><span class="pre">await</span> <span class="pre">f.read()</span></code> off the returned <code class="docutils literal notranslate"><span class="pre">UploadFile</span></code>.</p></td>
</tr>
<tr class="row-odd"><td><p>JSON serialization defaults to <code class="docutils literal notranslate"><span class="pre">ensure_ascii=False</span></code> (raw UTF-8)</p></td>
<td><p>5.6</p></td>
<td><p>No action for most apps. If you depend on <code class="docutils literal notranslate"><span class="pre">\uXXXX</span></code> escaping (or on exact <code class="docutils literal notranslate"><span class="pre">ETag</span></code> values over non-ASCII bodies), pass <code class="docutils literal notranslate"><span class="pre">API(json_ensure_ascii=True)</span></code>.</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">Vary:</span> <span class="pre">Accept</span></code> is sent by default on content-negotiated responses</p></td>
<td><p>5.1</p></td>
<td><p>No action (this is shared-cache-correct). To opt out, don’t set it / strip the header in middleware.</p></td>
</tr>
</tbody>
</table>
</section>
<section id="minor-invariant-fix">
<h2>Minor invariant fix<a class="headerlink" href="#minor-invariant-fix" title="Link to this heading"></a></h2>
<p><code class="docutils literal notranslate"><span class="pre">Route.__hash__</span></code> no longer includes <code class="docutils literal notranslate"><span class="pre">before_request</span></code>, so two routes that compare
equal now hash equal. This only affects code that put <code class="docutils literal notranslate"><span class="pre">Route</span></code> objects in a set or
dict keyed by identity-with-<code class="docutils literal notranslate"><span class="pre">before_request</span></code>, which is not a public pattern.</p>
</section>
<section id="not-changing">
<h2>Not changing<a class="headerlink" href="#not-changing" title="Link to this heading"></a></h2>
<p>The <code class="docutils literal notranslate"><span class="pre">(req,</span> <span class="pre">resp)</span></code> handler signature, the <code class="docutils literal notranslate"><span class="pre">Query(...)</span></code>-in-default marker form,
docstring-YAML OpenAPI overrides, and the permissive default <code class="docutils literal notranslate"><span class="pre">allowed_hosts=[&quot;*&quot;]</span></code>
all stay as they are.</p>
</section>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper"><p class="logo">
<a href="index.html">
<img class="logo" src="_static/responder.png" />
</a>
</p>
<p>
<strong>Responder</strong> — a familiar HTTP service framework for Python.
<br />
<small>v9.2.0</small>
</p>
<h3>Useful Links</h3>
<ul>
<li><a href="https://github.com/kennethreitz/responder">Responder @ GitHub</a></li>
<li><a href="https://pypi.org/project/responder/">Responder @ PyPI</a></li>
<li><a href="https://github.com/kennethreitz/responder/issues">Issue Tracker</a></li>
</ul><h3>Navigation</h3>
<p class="caption" role="heading"><span class="caption-text">User Guide</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="quickstart.html">Quick Start</a></li>
<li class="toctree-l1"><a class="reference internal" href="tour.html">Feature Tour</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="routers.html">Composing Apps with Routers</a></li>
<li class="toctree-l1"><a class="reference internal" href="guide-config.html">Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="clientgen.html">Generated Clients</a></li>
<li class="toctree-l1"><a class="reference internal" href="deployment.html">Deployment</a></li>
<li class="toctree-l1"><a class="reference internal" href="testing.html">Testing</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Tutorials</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="tutorial-rest.html">Building a REST API</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial-sqlalchemy.html">Using SQLAlchemy</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial-auth.html">Authentication</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial-websockets.html">WebSocket Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial-middleware.html">Writing Middleware</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial-flask.html">Migrating from Flask</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Reference</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="api.html">API Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="cli.html">Command Line Interface</a></li>
<li class="toctree-l1"><a class="reference internal" href="runtime-contracts.html">Runtime Contracts</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Project</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="changes.html">Changelog</a></li>
<li class="toctree-l1"><a class="reference internal" href="migration-v9.html">Migrating to v9</a></li>
<li class="toctree-l1"><a class="reference internal" href="migration-v8.html">Migrating to v8</a></li>
<li class="toctree-l1"><a class="reference internal" href="migration-v7.html">Migrating to v7</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Migrating to v6</a></li>
<li class="toctree-l1"><a class="reference internal" href="migration-v5.html">Migrating to v5</a></li>
<li class="toctree-l1"><a class="reference internal" href="sandbox.html">Sandbox</a></li>
<li class="toctree-l1"><a class="reference internal" href="backlog.html">Backlog</a></li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li>Previous: <a href="migration-v7.html" title="previous chapter">Migrating to v7</a></li>
<li>Next: <a href="migration-v5.html" title="next chapter">Migrating to Responder 5.0</a></li>
</ul></li>
</ul>
</div>
<search id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&#169;2018-2026, Kenneth Reitz.
|
<a href="_sources/migration-v6.md.txt"
rel="nofollow">Page source</a>
</div>
<a href="https://github.com/kennethreitz/responder" class="github">
<img src="_static/forkme_right_darkblue.png" alt="Fork me on GitHub" class="github"/>
</a>
</body>
</html>