<p dir="auto">Hi, I have a lots of <strong>unique</strong> fields in my database and I want to raise <strong>HTTPException</strong> with proper <strong>detail</strong> for each field that is duplicated.<br>
what is the best way to do it?</p>
<h3 dir="auto">First Check</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I added a very descriptive title to this issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I used the GitHub search to find a similar issue and didn't find it.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I searched the FastAPI documentation, with the integrated search.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already searched in Google "How to X in FastAPI" and didn't find any information.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already read and followed all the tutorial in the docs and didn't find an answer.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/samuelcolvin/pydantic">Pydantic</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/swagger-api/swagger-ui">Swagger UI</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/Redocly/redoc">ReDoc</a>.</li>
</ul>
<h3 dir="auto">Commit to Help</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I commit to help with one of those options <g-emoji class="g-emoji" alias="point_up_2" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f446.png">👆</g-emoji></li>
</ul>
<h3 dir="auto">Example Code</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from fastapi import FastAPI, Header, Depends

app = FastAPI()


async def some_header(some_header: str = Header(...)) -&gt; str:
    return some_header


async def some_dependency_one(test_header: str = Depends(some_header)) -&gt; str:
    return test_header + &quot;one&quot;


async def some_dependency_two(test_header: str = Depends(some_header)) -&gt; str:
    return test_header + &quot;two&quot;


@app.get(&quot;/&quot;)
async def root(
        some_dependency_one: str = Depends(some_dependency_one),
        some_dependency_two: str = Depends(some_dependency_two)
):
    return {&quot;1&quot;: some_dependency_one, &quot;2&quot;: some_dependency_two}"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">fastapi</span> <span class="pl-k">import</span> <span class="pl-v">FastAPI</span>, <span class="pl-v">Header</span>, <span class="pl-v">Depends</span>

<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">FastAPI</span>()


<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">some_header</span>(<span class="pl-s1">some_header</span>: <span class="pl-s1">str</span> <span class="pl-c1">=</span> <span class="pl-v">Header</span>(...)) <span class="pl-c1">-&gt;</span> <span class="pl-s1">str</span>:
    <span class="pl-k">return</span> <span class="pl-s1">some_header</span>


<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">some_dependency_one</span>(<span class="pl-s1">test_header</span>: <span class="pl-s1">str</span> <span class="pl-c1">=</span> <span class="pl-v">Depends</span>(<span class="pl-s1">some_header</span>)) <span class="pl-c1">-&gt;</span> <span class="pl-s1">str</span>:
    <span class="pl-k">return</span> <span class="pl-s1">test_header</span> <span class="pl-c1">+</span> <span class="pl-s">"one"</span>


<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">some_dependency_two</span>(<span class="pl-s1">test_header</span>: <span class="pl-s1">str</span> <span class="pl-c1">=</span> <span class="pl-v">Depends</span>(<span class="pl-s1">some_header</span>)) <span class="pl-c1">-&gt;</span> <span class="pl-s1">str</span>:
    <span class="pl-k">return</span> <span class="pl-s1">test_header</span> <span class="pl-c1">+</span> <span class="pl-s">"two"</span>


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">get</span>(<span class="pl-s">"/"</span>)</span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">root</span>(
        <span class="pl-s1">some_dependency_one</span>: <span class="pl-s1">str</span> <span class="pl-c1">=</span> <span class="pl-v">Depends</span>(<span class="pl-s1">some_dependency_one</span>),
        <span class="pl-s1">some_dependency_two</span>: <span class="pl-s1">str</span> <span class="pl-c1">=</span> <span class="pl-v">Depends</span>(<span class="pl-s1">some_dependency_two</span>)
):
    <span class="pl-k">return</span> {<span class="pl-s">"1"</span>: <span class="pl-s1">some_dependency_one</span>, <span class="pl-s">"2"</span>: <span class="pl-s1">some_dependency_two</span>}</pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">Curl the root path without the header "some_header":</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="curl -X 'GET' \
&gt;   'http://127.0.0.1:8000/' \
&gt;   -H 'accept: application/json' \
&gt;

{
	&quot;detail&quot;: [{
		&quot;loc&quot;: [&quot;header&quot;, &quot;some-header&quot;],
		&quot;msg&quot;: &quot;field required&quot;,
		&quot;type&quot;: &quot;value_error.missing&quot;
	}, {
		&quot;loc&quot;: [&quot;header&quot;, &quot;some-header&quot;],
		&quot;msg&quot;: &quot;field required&quot;,
		&quot;type&quot;: &quot;value_error.missing&quot;
	}]
}"><pre class="notranslate"><code class="notranslate">curl -X 'GET' \
&gt;   'http://127.0.0.1:8000/' \
&gt;   -H 'accept: application/json' \
&gt;

{
	"detail": [{
		"loc": ["header", "some-header"],
		"msg": "field required",
		"type": "value_error.missing"
	}, {
		"loc": ["header", "some-header"],
		"msg": "field required",
		"type": "value_error.missing"
	}]
}
</code></pre></div>
<p dir="auto">The missing header error is duplicated twice.</p>
<ol dir="auto">
<li>Is this expected?</li>
<li>I believe that, even if it is currently expected, as FastAPI is caching sub-dependencies according to <a href="https://fastapi.tiangolo.com/tutorial/dependencies/sub-dependencies/#using-the-same-dependency-multiple-times" rel="nofollow">https://fastapi.tiangolo.com/tutorial/dependencies/sub-dependencies/#using-the-same-dependency-multiple-times</a><br>
it should be possible to "de-duplicate" errors like this. So we could turn this "question" or "bug" report into a feature request :)</li>
</ol>
<h3 dir="auto">Operating System</h3>
<p dir="auto">macOS</p>
<h3 dir="auto">Operating System Details</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">FastAPI Version</h3>
<p dir="auto">0.68.2</p>
<h3 dir="auto">Python Version</h3>
<p dir="auto">3.9.6</p>
<h3 dir="auto">Additional Context</h3>
<p dir="auto"><em>No response</em></p>