<p dir="auto">Hello all, I'm new to FastAPI but I believe this is the right place to be posting this even though the issues I believe stems from Pydantic as I'm using it in the context of FastAPI. I'm running this in Pycharm 2020.2 but have also tried it outside of an IDE.</p>
<h3 dir="auto">Description</h3>
<p dir="auto">I've seen similar issues about self-referencing Pydantic models causing <code class="notranslate">RecursionError: maximum recursion depth exceeded in comparison</code> but as far as I can tell there are no self referencing models included.</p>
<p dir="auto">The code runs successfully until the function in <code class="notranslate">audit.py</code> tries to return the output from the model. I'm willing to state that its most likely something I've coded wrong so I've listed this as a question.</p>
<p dir="auto">The output is created correctly and I have checked this with debugging but the <code class="notranslate">output</code> is not returned and creates a 500 http status code when running from <code class="notranslate">http://127.0.0.1/docs#/audit/audit_api_v1_audit__post</code>.</p>
<p dir="auto">Thanks in advance and thank you for creating this wonderful framework!</p>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>OS: Windows 10</li>
<li>FastAPI Version: 0.61.1</li>
<li>Pydantic Version: 1.6.1</li>
<li>Uvicorn Version: 0.11.8</li>
<li>Python Version: 3.7.1</li>
<li>Pycharm Version: 2020.2</li>
</ul>
<h3 dir="auto">App</h3>
<p dir="auto"><code class="notranslate">main.py</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;&quot;
import uvicorn
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware


from app.api.routes.router import api_router
from app.core.logging import init_logging
from app.core.config import settings

init_logging()


def get_app() -&gt; FastAPI:
    application = FastAPI(title=settings.APP_NAME, version=settings.APP_VERSION, debug=settings.DEBUG)

    if settings.BACKEND_CORS_ORIGINS:
        # middleware support for cors
        application.add_middleware(
            CORSMiddleware,
            allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
            allow_credentials=True,
            allow_methods=[&quot;*&quot;],
            allow_headers=[&quot;*&quot;],
        )
    application.include_router(api_router, prefix=settings.API_V1_STR)
    return application


app = get_app()

if __name__ == &quot;__main__&quot;:
    uvicorn.run(&quot;main:app&quot;, host=&quot;127.0.0.1&quot;, port=80)
"><pre class="notranslate"><code class="notranslate">""
import uvicorn
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware


from app.api.routes.router import api_router
from app.core.logging import init_logging
from app.core.config import settings

init_logging()


def get_app() -&gt; FastAPI:
    application = FastAPI(title=settings.APP_NAME, version=settings.APP_VERSION, debug=settings.DEBUG)

    if settings.BACKEND_CORS_ORIGINS:
        # middleware support for cors
        application.add_middleware(
            CORSMiddleware,
            allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
            allow_credentials=True,
            allow_methods=["*"],
            allow_headers=["*"],
        )
    application.include_router(api_router, prefix=settings.API_V1_STR)
    return application


app = get_app()

if __name__ == "__main__":
    uvicorn.run("main:app", host="127.0.0.1", port=80)

</code></pre></div>
<p dir="auto"><code class="notranslate">router.py</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
from fastapi import APIRouter

from app.api.routes import audit

api_router = APIRouter()
api_router.include_router(audit.router, tags=[&quot;audit&quot;], prefix=&quot;/audit&quot;)"><pre class="notranslate"><code class="notranslate">
from fastapi import APIRouter

from app.api.routes import audit

api_router = APIRouter()
api_router.include_router(audit.router, tags=["audit"], prefix="/audit")
</code></pre></div>
<p dir="auto"><code class="notranslate">audit.py</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import validators
from fastapi import APIRouter, HTTPException
from loguru import logger

from app.api.dependencies.audit import analyzer
from app.schemas.audit import AuditPayload, AuditResult

router = APIRouter()


@router.post(&quot;/&quot;, response_model=AuditResult, name=&quot;audit&quot;, status_code=200)
async def post_audit(payload: AuditPayload) -&gt; AuditResult:
    logger.info(&quot;Audit request received&quot;)
    # validate URL
    try:
        logger.info(&quot;Validating URL&quot;)
        validators.url(payload.url)
    except HTTPException:
        HTTPException(status_code=404, detail=&quot;Invalid URL.&quot;)
        logger.exception(&quot;HTTPException - Invalid URL&quot;)

    # generate output from route audit.py
    logger.info(&quot;Running audit analysis. This could take up to 10 minutes. Maybe grab a coffee...&quot;)
    analyzed_output = analyzer.analyze(url=payload.url,
                                       brand=payload.brand,
                                       twitter_screen_name=payload.twitter_screen_name,
                                       facebook_page_name=payload.facebook_page_name,
                                       instagram_screen_name=payload.instagram_screen_name,
                                       youtube_user_name=payload.youtube_user_name,
                                       ignore_robots=payload.ignore_robots,
                                       ignore_sitemap=payload.ignore_sitemap,
                                       google_analytics_view_id=payload.google_analytics_view_id)
    output = AuditResult(**analyzed_output)
    return output "><pre class="notranslate"><code class="notranslate">import validators
from fastapi import APIRouter, HTTPException
from loguru import logger

from app.api.dependencies.audit import analyzer
from app.schemas.audit import AuditPayload, AuditResult

router = APIRouter()


@router.post("/", response_model=AuditResult, name="audit", status_code=200)
async def post_audit(payload: AuditPayload) -&gt; AuditResult:
    logger.info("Audit request received")
    # validate URL
    try:
        logger.info("Validating URL")
        validators.url(payload.url)
    except HTTPException:
        HTTPException(status_code=404, detail="Invalid URL.")
        logger.exception("HTTPException - Invalid URL")

    # generate output from route audit.py
    logger.info("Running audit analysis. This could take up to 10 minutes. Maybe grab a coffee...")
    analyzed_output = analyzer.analyze(url=payload.url,
                                       brand=payload.brand,
                                       twitter_screen_name=payload.twitter_screen_name,
                                       facebook_page_name=payload.facebook_page_name,
                                       instagram_screen_name=payload.instagram_screen_name,
                                       youtube_user_name=payload.youtube_user_name,
                                       ignore_robots=payload.ignore_robots,
                                       ignore_sitemap=payload.ignore_sitemap,
                                       google_analytics_view_id=payload.google_analytics_view_id)
    output = AuditResult(**analyzed_output)
    return output 
</code></pre></div>
<p dir="auto"><code class="notranslate">audit_models.py</code>.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from pydantic import BaseModel


class AuditPayload(BaseModel):
    url: str
    brand: str
    twitter_screen_name: str
    facebook_page_name: str
    instagram_screen_name: str
    youtube_user_name: str
    ignore_robots: bool
    ignore_sitemap: bool
    google_analytics_view_id: str


class AuditResult(BaseModel):
    base_url: str
    run_time: float
    website_404: dict
    website_302: dict
    website_h1_tags: dict
    website_duplicate_h1: dict
    website_h2_tags: dict
    website_page_duplications: dict
    website_page_similarities: dict
    website_page_desc_duplications: dict
    website_page_title_duplications: dict
    pages: list
    pages_out_links_404: dict = None
    pages_canonicals: dict
    seo_phrases: dict
    social: dict
    google_analytics_report: dict
    google_psi_desktop: dict
    google_psi_mobile: dict
    google_algo_updates: dict
    google_sb: list
    robots_txt: list
"><pre class="notranslate"><code class="notranslate">from pydantic import BaseModel


class AuditPayload(BaseModel):
    url: str
    brand: str
    twitter_screen_name: str
    facebook_page_name: str
    instagram_screen_name: str
    youtube_user_name: str
    ignore_robots: bool
    ignore_sitemap: bool
    google_analytics_view_id: str


class AuditResult(BaseModel):
    base_url: str
    run_time: float
    website_404: dict
    website_302: dict
    website_h1_tags: dict
    website_duplicate_h1: dict
    website_h2_tags: dict
    website_page_duplications: dict
    website_page_similarities: dict
    website_page_desc_duplications: dict
    website_page_title_duplications: dict
    pages: list
    pages_out_links_404: dict = None
    pages_canonicals: dict
    seo_phrases: dict
    social: dict
    google_analytics_report: dict
    google_psi_desktop: dict
    google_psi_mobile: dict
    google_algo_updates: dict
    google_sb: list
    robots_txt: list

</code></pre></div>
<p dir="auto">This line throws the error in the logs:<br>
2020-09-10 10:02:31.483 | ERROR    | uvicorn.protocols.http.h11_impl:run_asgi:391 - Exception in ASGI application</p>
<p dir="auto">I've included the full stack trace as I'm not sure which bit is most relevant, but I believe this has something to do with it:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  File &quot;pydantic\main.py&quot;, line 623, in pydantic.main.BaseModel._get_value
  [Previous line repeated 722 more times]"><pre class="notranslate"><code class="notranslate">  File "pydantic\main.py", line 623, in pydantic.main.BaseModel._get_value
  [Previous line repeated 722 more times]
</code></pre></div>
<p dir="auto">Full traceback:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  File &quot;C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\pydevconsole.py&quot;, line 483, in &lt;module&gt;
    pydevconsole.start_client(host, port)
    │            │            │     └ 50488
    │            │            └ '127.0.0.1'
    │            └ &lt;function start_client at 0x000001BCEDC19D08&gt;
    └ &lt;module 'pydevconsole' from 'C:\\Users\\&lt;user&gt;\\AppData\\Local\\JetBrains\\Toolbox\\apps\\PyCharm-P\\ch-0\\202.6948.78\\pl...
  File &quot;C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\pydevconsole.py&quot;, line 411, in start_client
    process_exec_queue(interpreter)
    │                  └ &lt;_pydev_bundle.pydev_ipython_console.InterpreterInterface object at 0x000001BCEDC1BF98&gt;
    └ &lt;function process_exec_queue at 0x000001BCEDC19A60&gt;
  File &quot;C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\pydevconsole.py&quot;, line 258, in process_exec_queue
    more = interpreter.add_exec(code_fragment)
           │           │        └ &lt;_pydev_bundle.pydev_console_types.CodeFragment object at 0x000001BCEDCFE748&gt;
           │           └ &lt;function BaseCodeExecutor.add_exec at 0x000001BCECF38488&gt;
           └ &lt;_pydev_bundle.pydev_ipython_console.InterpreterInterface object at 0x000001BCEDC1BF98&gt;
  File &quot;C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\_pydev_bundle\pydev_code_executor.py&quot;, line 106, in add_exec
    more = self.do_add_exec(code_fragment)
           │    │           └ &lt;_pydev_bundle.pydev_console_types.CodeFragment object at 0x000001BCEDCFE748&gt;
           │    └ &lt;function InterpreterInterface.do_add_exec at 0x000001BCEDC15D90&gt;
           └ &lt;_pydev_bundle.pydev_ipython_console.InterpreterInterface object at 0x000001BCEDC1BF98&gt;
  File &quot;C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\_pydev_bundle\pydev_ipython_console.py&quot;, line 36, in do_add_exec
    res = bool(self.interpreter.add_exec(code_fragment.text))
               │    │           │        │             └ &quot;runfile('E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app/main.py', wdir='E:/Users/&lt;user&gt;/Docume...
               │    │           │        └ &lt;_pydev_bundle.pydev_console_types.CodeFragment object at 0x000001BCEDCFE748&gt;
               │    │           └ &lt;function _PyDevFrontEnd.add_exec at 0x000001BCEDC15A60&gt;
               │    └ &lt;_pydev_bundle.pydev_ipython_console_011._PyDevFrontEnd object at 0x000001BCEDC350B8&gt;
               └ &lt;_pydev_bundle.pydev_ipython_console.InterpreterInterface object at 0x000001BCEDC1BF98&gt;
  File &quot;C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\_pydev_bundle\pydev_ipython_console_011.py&quot;, line 483, in add_exec
    self.ipython.run_cell(line, store_history=True)
    │    │       │        └ &quot;runfile('E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app/main.py', wdir='E:/Users/&lt;user&gt;/Docume...
    │    │       └ &lt;function InteractiveShell.run_cell at 0x000001BCED5E7268&gt;
    │    └ &lt;_pydev_bundle.pydev_ipython_console_011.PyDevTerminalInteractiveShell object at 0x000001BCEDC350F0&gt;
    └ &lt;_pydev_bundle.pydev_ipython_console_011._PyDevFrontEnd object at 0x000001BCEDC350B8&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\IPython\core\interactiveshell.py&quot;, line 2843, in run_cell
    raw_cell, store_history, silent, shell_futures)
    │         │              │       └ True
    │         │              └ False
    │         └ True
    └ &quot;runfile('E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app/main.py', wdir='E:/Users/&lt;user&gt;/Docume...
  File &quot;C:\Program Files\Python37\lib\site-packages\IPython\core\interactiveshell.py&quot;, line 2869, in _run_cell
    return runner(coro)
           │      └ &lt;generator object InteractiveShell.run_cell_async at 0x000001BCEDC49C78&gt;
           └ &lt;function _pseudo_sync_runner at 0x000001BCED5D0C80&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\IPython\core\async_helpers.py&quot;, line 67, in _pseudo_sync_runner
    coro.send(None)
    │    └ &lt;method 'send' of 'generator' objects&gt;
    └ &lt;generator object InteractiveShell.run_cell_async at 0x000001BCEDC49C78&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\IPython\core\interactiveshell.py&quot;, line 3044, in run_cell_async
    interactivity=interactivity, compiler=compiler, result=result)
                  │                       │                └ &lt;ExecutionResult object at 1bcedcd3470, execution_count=2 error_before_exec=None error_in_exec=None info=&lt;ExecutionInfo objec...
                  │                       └ &lt;IPython.core.compilerop.CachingCompiler object at 0x000001BCEDC356D8&gt;
                  └ 'last_expr'
  File &quot;C:\Program Files\Python37\lib\site-packages\IPython\core\interactiveshell.py&quot;, line 3215, in run_ast_nodes
    if (yield from self.run_code(code, result)):
                   │    │        │     └ &lt;ExecutionResult object at 1bcedcd3470, execution_count=2 error_before_exec=None error_in_exec=None info=&lt;ExecutionInfo objec...
                   │    │        └ &lt;code object &lt;module&gt; at 0x000001BCEDCDADB0, file &quot;&lt;ipython-input-2-086756a0f1dd&gt;&quot;, line 1&gt;
                   │    └ &lt;function InteractiveShell.run_code at 0x000001BCED5E76A8&gt;
                   └ &lt;_pydev_bundle.pydev_ipython_console_011.PyDevTerminalInteractiveShell object at 0x000001BCEDC350F0&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\IPython\core\interactiveshell.py&quot;, line 3291, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
         │         │    │               │    └ {'__name__': 'pydev_umd', '__doc__': 'Automatically created module for IPython interactive environment', '__package__': None,...
         │         │    │               └ &lt;_pydev_bundle.pydev_ipython_console_011.PyDevTerminalInteractiveShell object at 0x000001BCEDC350F0&gt;
         │         │    └ &lt;property object at 0x000001BCED5D8958&gt;
         │         └ &lt;_pydev_bundle.pydev_ipython_console_011.PyDevTerminalInteractiveShell object at 0x000001BCEDC350F0&gt;
         └ &lt;code object &lt;module&gt; at 0x000001BCEDCDADB0, file &quot;&lt;ipython-input-2-086756a0f1dd&gt;&quot;, line 1&gt;
  File &quot;&lt;ipython-input-2-086756a0f1dd&gt;&quot;, line 1, in &lt;module&gt;
    runfile('E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app/main.py', wdir='E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app')
  File &quot;C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py&quot;, line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
    │             │        │         │            └ {'__name__': '__main__', '__doc__': &quot;\nMain entry point into API for endpoints related to HawkSense's main functionality.\nto...
    │             │        │         └ {'__name__': '__main__', '__doc__': &quot;\nMain entry point into API for endpoints related to HawkSense's main functionality.\nto...
    │             │        └ 'E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app/main.py'
    │             └ &lt;function execfile at 0x000001BCECC521E0&gt;
    └ &lt;module '_pydev_bundle.pydev_imports' from 'C:\\Users\\&lt;user&gt;\\AppData\\Local\\JetBrains\\Toolbox\\apps\\PyCharm-P\\ch-0\\...
  File &quot;C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py&quot;, line 18, in execfile
    exec(compile(contents+&quot;\n&quot;, file, 'exec'), glob, loc)
                 │              │              │     └ {'__name__': '__main__', '__doc__': &quot;\nMain entry point into API for endpoints related to HawkSense's main functionality.\nto...
                 │              │              └ {'__name__': '__main__', '__doc__': &quot;\nMain entry point into API for endpoints related to HawkSense's main functionality.\nto...
                 │              └ 'E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app/main.py'
                 └ '#!/usr/bin/env python\n\n&quot;&quot;&quot;\nMain entry point into API for endpoints related to HawkSense\'s main functionality.\ntodo: htt...
  File &quot;E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app\main.py&quot;, line 47, in &lt;module&gt;
    uvicorn.run(&quot;main:app&quot;, host=&quot;127.0.0.1&quot;, port=80)  # for debug only
    │       └ &lt;function run at 0x000001BCEDE041E0&gt;
    └ &lt;module 'uvicorn' from 'C:\\Program Files\\Python37\\lib\\site-packages\\uvicorn\\__init__.py'&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\uvicorn\main.py&quot;, line 362, in run
    server.run()
    │      └ &lt;function Server.run at 0x000001BCEDE4B510&gt;
    └ &lt;uvicorn.main.Server object at 0x000001BCFC722198&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\uvicorn\main.py&quot;, line 390, in run
    loop.run_until_complete(self.serve(sockets=sockets))
    │    │                  │    │             └ None
    │    │                  │    └ &lt;function Server.serve at 0x000001BCEDE4B598&gt;
    │    │                  └ &lt;uvicorn.main.Server object at 0x000001BCFC722198&gt;
    │    └ &lt;function BaseEventLoop.run_until_complete at 0x000001BCED49FE18&gt;
    └ &lt;_WindowsSelectorEventLoop running=True closed=False debug=False&gt;
  File &quot;C:\Program Files\Python37\lib\asyncio\base_events.py&quot;, line 560, in run_until_complete
    self.run_forever()
    │    └ &lt;function BaseEventLoop.run_forever at 0x000001BCED49FD90&gt;
    └ &lt;_WindowsSelectorEventLoop running=True closed=False debug=False&gt;
  File &quot;C:\Program Files\Python37\lib\asyncio\base_events.py&quot;, line 528, in run_forever
    self._run_once()
    │    └ &lt;function BaseEventLoop._run_once at 0x000001BCED4A27B8&gt;
    └ &lt;_WindowsSelectorEventLoop running=True closed=False debug=False&gt;
  File &quot;C:\Program Files\Python37\lib\asyncio\base_events.py&quot;, line 1764, in _run_once
    handle._run()
    │      └ &lt;function Handle._run at 0x000001BCED43AB70&gt;
    └ &lt;Handle &lt;TaskStepMethWrapper object at 0x000001BCFC7D4B00&gt;()&gt;
  File &quot;C:\Program Files\Python37\lib\asyncio\events.py&quot;, line 88, in _run
    self._context.run(self._callback, *self._args)
    │    │            │    │           │    └ &lt;member '_args' of 'Handle' objects&gt;
    │    │            │    │           └ &lt;Handle &lt;TaskStepMethWrapper object at 0x000001BCFC7D4B00&gt;()&gt;
    │    │            │    └ &lt;member '_callback' of 'Handle' objects&gt;
    │    │            └ &lt;Handle &lt;TaskStepMethWrapper object at 0x000001BCFC7D4B00&gt;()&gt;
    │    └ &lt;member '_context' of 'Handle' objects&gt;
    └ &lt;Handle &lt;TaskStepMethWrapper object at 0x000001BCFC7D4B00&gt;()&gt;
&gt; File &quot;C:\Program Files\Python37\lib\site-packages\uvicorn\protocols\http\h11_impl.py&quot;, line 388, in run_asgi
    result = await app(self.scope, self.receive, self.send)
                   │   │    │      │    │        │    └ &lt;function RequestResponseCycle.send at 0x000001BCFC757840&gt;
                   │   │    │      │    │        └ &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4A90&gt;
                   │   │    │      │    └ &lt;function RequestResponseCycle.receive at 0x000001BCFC7578C8&gt;
                   │   │    │      └ &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4A90&gt;
                   │   │    └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
                   │   └ &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4A90&gt;
                   └ &lt;uvicorn.middleware.proxy_headers.ProxyHeadersMiddleware object at 0x000001BCFC722BA8&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\uvicorn\middleware\proxy_headers.py&quot;, line 45, in __call__
    return await self.app(scope, receive, send)
                 │    │   │      │        └ &lt;bound method RequestResponseCycle.send of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4A90&gt;&gt;
                 │    │   │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
                 │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
                 │    └ &lt;fastapi.applications.FastAPI object at 0x000001BCFC722710&gt;
                 └ &lt;uvicorn.middleware.proxy_headers.ProxyHeadersMiddleware object at 0x000001BCFC722BA8&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\fastapi\applications.py&quot;, line 149, in __call__
    await super().__call__(scope, receive, send)
                           │      │        └ &lt;bound method RequestResponseCycle.send of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4A90&gt;&gt;
                           │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
                           └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
  File &quot;C:\Program Files\Python37\lib\site-packages\starlette\applications.py&quot;, line 102, in __call__
    await self.middleware_stack(scope, receive, send)
          │    │                │      │        └ &lt;bound method RequestResponseCycle.send of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4A90&gt;&gt;
          │    │                │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │    │                └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │    └ &lt;starlette.middleware.errors.ServerErrorMiddleware object at 0x000001BCFC7B8FD0&gt;
          └ &lt;fastapi.applications.FastAPI object at 0x000001BCFC722710&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\starlette\middleware\errors.py&quot;, line 181, in __call__
    raise exc from None
  File &quot;C:\Program Files\Python37\lib\site-packages\starlette\middleware\errors.py&quot;, line 159, in __call__
    await self.app(scope, receive, _send)
          │    │   │      │        └ &lt;function ServerErrorMiddleware.__call__.&lt;locals&gt;._send at 0x000001BCFC72AE18&gt;
          │    │   │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │    └ &lt;starlette.middleware.cors.CORSMiddleware object at 0x000001BCFC7B8F60&gt;
          └ &lt;starlette.middleware.errors.ServerErrorMiddleware object at 0x000001BCFC7B8FD0&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\starlette\middleware\cors.py&quot;, line 84, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
          │    │               │      │        │                     └ Headers({'host': '127.0.0.1', 'connection': 'keep-alive', 'content-length': '295', 'accept': 'application/json', 'user-agent'...
          │    │               │      │        └ &lt;function ServerErrorMiddleware.__call__.&lt;locals&gt;._send at 0x000001BCFC72AE18&gt;
          │    │               │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │    │               └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │    └ &lt;function CORSMiddleware.simple_response at 0x000001BCEE53DC80&gt;
          └ &lt;starlette.middleware.cors.CORSMiddleware object at 0x000001BCFC7B8F60&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\starlette\middleware\cors.py&quot;, line 140, in simple_response
    await self.app(scope, receive, send)
          │    │   │      │        └ functools.partial(&lt;bound method CORSMiddleware.send of &lt;starlette.middleware.cors.CORSMiddleware object at 0x000001BCFC7B8F60...
          │    │   │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │    └ &lt;starlette.exceptions.ExceptionMiddleware object at 0x000001BCFC7B8E48&gt;
          └ &lt;starlette.middleware.cors.CORSMiddleware object at 0x000001BCFC7B8F60&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\starlette\exceptions.py&quot;, line 82, in __call__
    raise exc from None
  File &quot;C:\Program Files\Python37\lib\site-packages\starlette\exceptions.py&quot;, line 71, in __call__
    await self.app(scope, receive, sender)
          │    │   │      │        └ &lt;function ExceptionMiddleware.__call__.&lt;locals&gt;.sender at 0x000001BCFC7C18C8&gt;
          │    │   │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │    └ &lt;fastapi.routing.APIRouter object at 0x000001BCFC7220F0&gt;
          └ &lt;starlette.exceptions.ExceptionMiddleware object at 0x000001BCFC7B8E48&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\starlette\routing.py&quot;, line 550, in __call__
    await route.handle(scope, receive, send)
          │     │      │      │        └ &lt;function ExceptionMiddleware.__call__.&lt;locals&gt;.sender at 0x000001BCFC7C18C8&gt;
          │     │      │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │     │      └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │     └ &lt;function Route.handle at 0x000001BCEE4FF6A8&gt;
          └ &lt;fastapi.routing.APIRoute object at 0x000001BCFC7B8E80&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\starlette\routing.py&quot;, line 227, in handle
    await self.app(scope, receive, send)
          │    │   │      │        └ &lt;function ExceptionMiddleware.__call__.&lt;locals&gt;.sender at 0x000001BCFC7C18C8&gt;
          │    │   │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │    └ &lt;function request_response.&lt;locals&gt;.app at 0x000001BCFC7C1A60&gt;
          └ &lt;fastapi.routing.APIRoute object at 0x000001BCFC7B8E80&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\starlette\routing.py&quot;, line 41, in app
    response = await func(request)
                     │    └ &lt;starlette.requests.Request object at 0x000001BCFC7D4588&gt;
                     └ &lt;function get_request_handler.&lt;locals&gt;.app at 0x000001BCFC7C19D8&gt;
  File &quot;C:\Program Files\Python37\lib\site-packages\fastapi\routing.py&quot;, line 213, in app
    is_coroutine=is_coroutine,
                 └ True
  File &quot;C:\Program Files\Python37\lib\site-packages\fastapi\routing.py&quot;, line 113, in serialize_response
    exclude_none=exclude_none,
                 └ False
  File &quot;C:\Program Files\Python37\lib\site-packages\fastapi\routing.py&quot;, line 65, in _prepare_response_content
    exclude_none=exclude_none,
                 └ False
  File &quot;pydantic\main.py&quot;, line 386, in pydantic.main.BaseModel.dict
  File &quot;pydantic\main.py&quot;, line 706, in _iter
  File &quot;pydantic\main.py&quot;, line 623, in pydantic.main.BaseModel._get_value
  File &quot;pydantic\main.py&quot;, line 623, in pydantic.main.BaseModel._get_value
  File &quot;pydantic\main.py&quot;, line 623, in pydantic.main.BaseModel._get_value
  [Previous line repeated 722 more times]
  File &quot;pydantic\main.py&quot;, line 605, in pydantic.main.BaseModel._get_value
  File &quot;C:\Program Files\Python37\lib\abc.py&quot;, line 139, in __instancecheck__
    return _abc_instancecheck(cls, instance)
           │                  │    └ 8
           │                  └ &lt;class 'pydantic.main.BaseModel'&gt;
           └ &lt;built-in function _abc_instancecheck&gt;
RecursionError: maximum recursion depth exceeded in comparison```



"><pre lang="Traceback" class="notranslate"><code class="notranslate">  File "C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\pydevconsole.py", line 483, in &lt;module&gt;
    pydevconsole.start_client(host, port)
    │            │            │     └ 50488
    │            │            └ '127.0.0.1'
    │            └ &lt;function start_client at 0x000001BCEDC19D08&gt;
    └ &lt;module 'pydevconsole' from 'C:\\Users\\&lt;user&gt;\\AppData\\Local\\JetBrains\\Toolbox\\apps\\PyCharm-P\\ch-0\\202.6948.78\\pl...
  File "C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\pydevconsole.py", line 411, in start_client
    process_exec_queue(interpreter)
    │                  └ &lt;_pydev_bundle.pydev_ipython_console.InterpreterInterface object at 0x000001BCEDC1BF98&gt;
    └ &lt;function process_exec_queue at 0x000001BCEDC19A60&gt;
  File "C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\pydevconsole.py", line 258, in process_exec_queue
    more = interpreter.add_exec(code_fragment)
           │           │        └ &lt;_pydev_bundle.pydev_console_types.CodeFragment object at 0x000001BCEDCFE748&gt;
           │           └ &lt;function BaseCodeExecutor.add_exec at 0x000001BCECF38488&gt;
           └ &lt;_pydev_bundle.pydev_ipython_console.InterpreterInterface object at 0x000001BCEDC1BF98&gt;
  File "C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\_pydev_bundle\pydev_code_executor.py", line 106, in add_exec
    more = self.do_add_exec(code_fragment)
           │    │           └ &lt;_pydev_bundle.pydev_console_types.CodeFragment object at 0x000001BCEDCFE748&gt;
           │    └ &lt;function InterpreterInterface.do_add_exec at 0x000001BCEDC15D90&gt;
           └ &lt;_pydev_bundle.pydev_ipython_console.InterpreterInterface object at 0x000001BCEDC1BF98&gt;
  File "C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\_pydev_bundle\pydev_ipython_console.py", line 36, in do_add_exec
    res = bool(self.interpreter.add_exec(code_fragment.text))
               │    │           │        │             └ "runfile('E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app/main.py', wdir='E:/Users/&lt;user&gt;/Docume...
               │    │           │        └ &lt;_pydev_bundle.pydev_console_types.CodeFragment object at 0x000001BCEDCFE748&gt;
               │    │           └ &lt;function _PyDevFrontEnd.add_exec at 0x000001BCEDC15A60&gt;
               │    └ &lt;_pydev_bundle.pydev_ipython_console_011._PyDevFrontEnd object at 0x000001BCEDC350B8&gt;
               └ &lt;_pydev_bundle.pydev_ipython_console.InterpreterInterface object at 0x000001BCEDC1BF98&gt;
  File "C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\_pydev_bundle\pydev_ipython_console_011.py", line 483, in add_exec
    self.ipython.run_cell(line, store_history=True)
    │    │       │        └ "runfile('E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app/main.py', wdir='E:/Users/&lt;user&gt;/Docume...
    │    │       └ &lt;function InteractiveShell.run_cell at 0x000001BCED5E7268&gt;
    │    └ &lt;_pydev_bundle.pydev_ipython_console_011.PyDevTerminalInteractiveShell object at 0x000001BCEDC350F0&gt;
    └ &lt;_pydev_bundle.pydev_ipython_console_011._PyDevFrontEnd object at 0x000001BCEDC350B8&gt;
  File "C:\Program Files\Python37\lib\site-packages\IPython\core\interactiveshell.py", line 2843, in run_cell
    raw_cell, store_history, silent, shell_futures)
    │         │              │       └ True
    │         │              └ False
    │         └ True
    └ "runfile('E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app/main.py', wdir='E:/Users/&lt;user&gt;/Docume...
  File "C:\Program Files\Python37\lib\site-packages\IPython\core\interactiveshell.py", line 2869, in _run_cell
    return runner(coro)
           │      └ &lt;generator object InteractiveShell.run_cell_async at 0x000001BCEDC49C78&gt;
           └ &lt;function _pseudo_sync_runner at 0x000001BCED5D0C80&gt;
  File "C:\Program Files\Python37\lib\site-packages\IPython\core\async_helpers.py", line 67, in _pseudo_sync_runner
    coro.send(None)
    │    └ &lt;method 'send' of 'generator' objects&gt;
    └ &lt;generator object InteractiveShell.run_cell_async at 0x000001BCEDC49C78&gt;
  File "C:\Program Files\Python37\lib\site-packages\IPython\core\interactiveshell.py", line 3044, in run_cell_async
    interactivity=interactivity, compiler=compiler, result=result)
                  │                       │                └ &lt;ExecutionResult object at 1bcedcd3470, execution_count=2 error_before_exec=None error_in_exec=None info=&lt;ExecutionInfo objec...
                  │                       └ &lt;IPython.core.compilerop.CachingCompiler object at 0x000001BCEDC356D8&gt;
                  └ 'last_expr'
  File "C:\Program Files\Python37\lib\site-packages\IPython\core\interactiveshell.py", line 3215, in run_ast_nodes
    if (yield from self.run_code(code, result)):
                   │    │        │     └ &lt;ExecutionResult object at 1bcedcd3470, execution_count=2 error_before_exec=None error_in_exec=None info=&lt;ExecutionInfo objec...
                   │    │        └ &lt;code object &lt;module&gt; at 0x000001BCEDCDADB0, file "&lt;ipython-input-2-086756a0f1dd&gt;", line 1&gt;
                   │    └ &lt;function InteractiveShell.run_code at 0x000001BCED5E76A8&gt;
                   └ &lt;_pydev_bundle.pydev_ipython_console_011.PyDevTerminalInteractiveShell object at 0x000001BCEDC350F0&gt;
  File "C:\Program Files\Python37\lib\site-packages\IPython\core\interactiveshell.py", line 3291, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
         │         │    │               │    └ {'__name__': 'pydev_umd', '__doc__': 'Automatically created module for IPython interactive environment', '__package__': None,...
         │         │    │               └ &lt;_pydev_bundle.pydev_ipython_console_011.PyDevTerminalInteractiveShell object at 0x000001BCEDC350F0&gt;
         │         │    └ &lt;property object at 0x000001BCED5D8958&gt;
         │         └ &lt;_pydev_bundle.pydev_ipython_console_011.PyDevTerminalInteractiveShell object at 0x000001BCEDC350F0&gt;
         └ &lt;code object &lt;module&gt; at 0x000001BCEDCDADB0, file "&lt;ipython-input-2-086756a0f1dd&gt;", line 1&gt;
  File "&lt;ipython-input-2-086756a0f1dd&gt;", line 1, in &lt;module&gt;
    runfile('E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app/main.py', wdir='E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app')
  File "C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
    │             │        │         │            └ {'__name__': '__main__', '__doc__': "\nMain entry point into API for endpoints related to HawkSense's main functionality.\nto...
    │             │        │         └ {'__name__': '__main__', '__doc__': "\nMain entry point into API for endpoints related to HawkSense's main functionality.\nto...
    │             │        └ 'E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app/main.py'
    │             └ &lt;function execfile at 0x000001BCECC521E0&gt;
    └ &lt;module '_pydev_bundle.pydev_imports' from 'C:\\Users\\&lt;user&gt;\\AppData\\Local\\JetBrains\\Toolbox\\apps\\PyCharm-P\\ch-0\\...
  File "C:\Users\&lt;user&gt;\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\202.6948.78\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
                 │              │              │     └ {'__name__': '__main__', '__doc__': "\nMain entry point into API for endpoints related to HawkSense's main functionality.\nto...
                 │              │              └ {'__name__': '__main__', '__doc__': "\nMain entry point into API for endpoints related to HawkSense's main functionality.\nto...
                 │              └ 'E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app/main.py'
                 └ '#!/usr/bin/env python\n\n"""\nMain entry point into API for endpoints related to HawkSense\'s main functionality.\ntodo: htt...
  File "E:/Users/&lt;user&gt;/Documents/GitHub/HawkSense/backend/app/app\main.py", line 47, in &lt;module&gt;
    uvicorn.run("main:app", host="127.0.0.1", port=80)  # for debug only
    │       └ &lt;function run at 0x000001BCEDE041E0&gt;
    └ &lt;module 'uvicorn' from 'C:\\Program Files\\Python37\\lib\\site-packages\\uvicorn\\__init__.py'&gt;
  File "C:\Program Files\Python37\lib\site-packages\uvicorn\main.py", line 362, in run
    server.run()
    │      └ &lt;function Server.run at 0x000001BCEDE4B510&gt;
    └ &lt;uvicorn.main.Server object at 0x000001BCFC722198&gt;
  File "C:\Program Files\Python37\lib\site-packages\uvicorn\main.py", line 390, in run
    loop.run_until_complete(self.serve(sockets=sockets))
    │    │                  │    │             └ None
    │    │                  │    └ &lt;function Server.serve at 0x000001BCEDE4B598&gt;
    │    │                  └ &lt;uvicorn.main.Server object at 0x000001BCFC722198&gt;
    │    └ &lt;function BaseEventLoop.run_until_complete at 0x000001BCED49FE18&gt;
    └ &lt;_WindowsSelectorEventLoop running=True closed=False debug=False&gt;
  File "C:\Program Files\Python37\lib\asyncio\base_events.py", line 560, in run_until_complete
    self.run_forever()
    │    └ &lt;function BaseEventLoop.run_forever at 0x000001BCED49FD90&gt;
    └ &lt;_WindowsSelectorEventLoop running=True closed=False debug=False&gt;
  File "C:\Program Files\Python37\lib\asyncio\base_events.py", line 528, in run_forever
    self._run_once()
    │    └ &lt;function BaseEventLoop._run_once at 0x000001BCED4A27B8&gt;
    └ &lt;_WindowsSelectorEventLoop running=True closed=False debug=False&gt;
  File "C:\Program Files\Python37\lib\asyncio\base_events.py", line 1764, in _run_once
    handle._run()
    │      └ &lt;function Handle._run at 0x000001BCED43AB70&gt;
    └ &lt;Handle &lt;TaskStepMethWrapper object at 0x000001BCFC7D4B00&gt;()&gt;
  File "C:\Program Files\Python37\lib\asyncio\events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
    │    │            │    │           │    └ &lt;member '_args' of 'Handle' objects&gt;
    │    │            │    │           └ &lt;Handle &lt;TaskStepMethWrapper object at 0x000001BCFC7D4B00&gt;()&gt;
    │    │            │    └ &lt;member '_callback' of 'Handle' objects&gt;
    │    │            └ &lt;Handle &lt;TaskStepMethWrapper object at 0x000001BCFC7D4B00&gt;()&gt;
    │    └ &lt;member '_context' of 'Handle' objects&gt;
    └ &lt;Handle &lt;TaskStepMethWrapper object at 0x000001BCFC7D4B00&gt;()&gt;
&gt; File "C:\Program Files\Python37\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 388, in run_asgi
    result = await app(self.scope, self.receive, self.send)
                   │   │    │      │    │        │    └ &lt;function RequestResponseCycle.send at 0x000001BCFC757840&gt;
                   │   │    │      │    │        └ &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4A90&gt;
                   │   │    │      │    └ &lt;function RequestResponseCycle.receive at 0x000001BCFC7578C8&gt;
                   │   │    │      └ &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4A90&gt;
                   │   │    └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
                   │   └ &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4A90&gt;
                   └ &lt;uvicorn.middleware.proxy_headers.ProxyHeadersMiddleware object at 0x000001BCFC722BA8&gt;
  File "C:\Program Files\Python37\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
                 │    │   │      │        └ &lt;bound method RequestResponseCycle.send of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4A90&gt;&gt;
                 │    │   │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
                 │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
                 │    └ &lt;fastapi.applications.FastAPI object at 0x000001BCFC722710&gt;
                 └ &lt;uvicorn.middleware.proxy_headers.ProxyHeadersMiddleware object at 0x000001BCFC722BA8&gt;
  File "C:\Program Files\Python37\lib\site-packages\fastapi\applications.py", line 149, in __call__
    await super().__call__(scope, receive, send)
                           │      │        └ &lt;bound method RequestResponseCycle.send of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4A90&gt;&gt;
                           │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
                           └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
  File "C:\Program Files\Python37\lib\site-packages\starlette\applications.py", line 102, in __call__
    await self.middleware_stack(scope, receive, send)
          │    │                │      │        └ &lt;bound method RequestResponseCycle.send of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4A90&gt;&gt;
          │    │                │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │    │                └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │    └ &lt;starlette.middleware.errors.ServerErrorMiddleware object at 0x000001BCFC7B8FD0&gt;
          └ &lt;fastapi.applications.FastAPI object at 0x000001BCFC722710&gt;
  File "C:\Program Files\Python37\lib\site-packages\starlette\middleware\errors.py", line 181, in __call__
    raise exc from None
  File "C:\Program Files\Python37\lib\site-packages\starlette\middleware\errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
          │    │   │      │        └ &lt;function ServerErrorMiddleware.__call__.&lt;locals&gt;._send at 0x000001BCFC72AE18&gt;
          │    │   │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │    └ &lt;starlette.middleware.cors.CORSMiddleware object at 0x000001BCFC7B8F60&gt;
          └ &lt;starlette.middleware.errors.ServerErrorMiddleware object at 0x000001BCFC7B8FD0&gt;
  File "C:\Program Files\Python37\lib\site-packages\starlette\middleware\cors.py", line 84, in __call__
    await self.simple_response(scope, receive, send, request_headers=headers)
          │    │               │      │        │                     └ Headers({'host': '127.0.0.1', 'connection': 'keep-alive', 'content-length': '295', 'accept': 'application/json', 'user-agent'...
          │    │               │      │        └ &lt;function ServerErrorMiddleware.__call__.&lt;locals&gt;._send at 0x000001BCFC72AE18&gt;
          │    │               │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │    │               └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │    └ &lt;function CORSMiddleware.simple_response at 0x000001BCEE53DC80&gt;
          └ &lt;starlette.middleware.cors.CORSMiddleware object at 0x000001BCFC7B8F60&gt;
  File "C:\Program Files\Python37\lib\site-packages\starlette\middleware\cors.py", line 140, in simple_response
    await self.app(scope, receive, send)
          │    │   │      │        └ functools.partial(&lt;bound method CORSMiddleware.send of &lt;starlette.middleware.cors.CORSMiddleware object at 0x000001BCFC7B8F60...
          │    │   │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │    └ &lt;starlette.exceptions.ExceptionMiddleware object at 0x000001BCFC7B8E48&gt;
          └ &lt;starlette.middleware.cors.CORSMiddleware object at 0x000001BCFC7B8F60&gt;
  File "C:\Program Files\Python37\lib\site-packages\starlette\exceptions.py", line 82, in __call__
    raise exc from None
  File "C:\Program Files\Python37\lib\site-packages\starlette\exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
          │    │   │      │        └ &lt;function ExceptionMiddleware.__call__.&lt;locals&gt;.sender at 0x000001BCFC7C18C8&gt;
          │    │   │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │    └ &lt;fastapi.routing.APIRouter object at 0x000001BCFC7220F0&gt;
          └ &lt;starlette.exceptions.ExceptionMiddleware object at 0x000001BCFC7B8E48&gt;
  File "C:\Program Files\Python37\lib\site-packages\starlette\routing.py", line 550, in __call__
    await route.handle(scope, receive, send)
          │     │      │      │        └ &lt;function ExceptionMiddleware.__call__.&lt;locals&gt;.sender at 0x000001BCFC7C18C8&gt;
          │     │      │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │     │      └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │     └ &lt;function Route.handle at 0x000001BCEE4FF6A8&gt;
          └ &lt;fastapi.routing.APIRoute object at 0x000001BCFC7B8E80&gt;
  File "C:\Program Files\Python37\lib\site-packages\starlette\routing.py", line 227, in handle
    await self.app(scope, receive, send)
          │    │   │      │        └ &lt;function ExceptionMiddleware.__call__.&lt;locals&gt;.sender at 0x000001BCFC7C18C8&gt;
          │    │   │      └ &lt;bound method RequestResponseCycle.receive of &lt;uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x000001BCFC7D4...
          │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.1'}, 'http_version': '1.1', 'server': ('127.0.0.1', 80), 'clie...
          │    └ &lt;function request_response.&lt;locals&gt;.app at 0x000001BCFC7C1A60&gt;
          └ &lt;fastapi.routing.APIRoute object at 0x000001BCFC7B8E80&gt;
  File "C:\Program Files\Python37\lib\site-packages\starlette\routing.py", line 41, in app
    response = await func(request)
                     │    └ &lt;starlette.requests.Request object at 0x000001BCFC7D4588&gt;
                     └ &lt;function get_request_handler.&lt;locals&gt;.app at 0x000001BCFC7C19D8&gt;
  File "C:\Program Files\Python37\lib\site-packages\fastapi\routing.py", line 213, in app
    is_coroutine=is_coroutine,
                 └ True
  File "C:\Program Files\Python37\lib\site-packages\fastapi\routing.py", line 113, in serialize_response
    exclude_none=exclude_none,
                 └ False
  File "C:\Program Files\Python37\lib\site-packages\fastapi\routing.py", line 65, in _prepare_response_content
    exclude_none=exclude_none,
                 └ False
  File "pydantic\main.py", line 386, in pydantic.main.BaseModel.dict
  File "pydantic\main.py", line 706, in _iter
  File "pydantic\main.py", line 623, in pydantic.main.BaseModel._get_value
  File "pydantic\main.py", line 623, in pydantic.main.BaseModel._get_value
  File "pydantic\main.py", line 623, in pydantic.main.BaseModel._get_value
  [Previous line repeated 722 more times]
  File "pydantic\main.py", line 605, in pydantic.main.BaseModel._get_value
  File "C:\Program Files\Python37\lib\abc.py", line 139, in __instancecheck__
    return _abc_instancecheck(cls, instance)
           │                  │    └ 8
           │                  └ &lt;class 'pydantic.main.BaseModel'&gt;
           └ &lt;built-in function _abc_instancecheck&gt;
RecursionError: maximum recursion depth exceeded in comparison```




</code></pre></div>
<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 👆</li>
</ul>
<h3 dir="auto">Example Code</h3>
<p dir="auto">Here's <code class="notranslate">conftest.py</code> where I attempt to define a fixture that takes care of creating a test PostgreSQL database in the beginning of the test session, and dropping it after the test suite is done running:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Base = declarative_base()


@pytest.fixture(scope=&quot;session&quot;)
def db_engine():
    default_db = (
        &quot;postgresql+asyncpg://postgres:postgres@postgres:5432/postgres&quot;
    )
    test_db = &quot;postgresql+asyncpg://postgres:postgres@postgres:5432/test&quot;
    engine = create_async_engine(default_db)
    if not database_exists(test_db):  # &lt;- Getting error on this line
        create_database(test_db)

    Base.metadata.create_all(bind=engine)
    yield engine


@pytest.fixture(scope=&quot;function&quot;)
def db(db_engine):
    connection = db_engine.connect()

    # begin a non-ORM transaction
    connection.begin()

    # bind an individual Session to the connection
    Session = sessionmaker(bind=connection)
    db = Session()
    # db = Session(db_engine)

    yield db

    db.rollback()
    connection.close()


@pytest.fixture(scope=&quot;function&quot;)
def client(db):
    app.dependency_overrides[get_session] = lambda: db

    PREFIX = &quot;/api/v1/my-endpoint&quot;
    with TestClient(PREFIX, app) as c:
        yield c"><pre class="notranslate"><span class="pl-v">Base</span> <span class="pl-c1">=</span> <span class="pl-en">declarative_base</span>()


<span class="pl-en">@<span class="pl-s1">pytest</span>.<span class="pl-en">fixture</span>(<span class="pl-s1">scope</span><span class="pl-c1">=</span><span class="pl-s">"session"</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">db_engine</span>():
    <span class="pl-s1">default_db</span> <span class="pl-c1">=</span> (
        <span class="pl-s">"postgresql+asyncpg://postgres:postgres@postgres:5432/postgres"</span>
    )
    <span class="pl-s1">test_db</span> <span class="pl-c1">=</span> <span class="pl-s">"postgresql+asyncpg://postgres:postgres@postgres:5432/test"</span>
    <span class="pl-s1">engine</span> <span class="pl-c1">=</span> <span class="pl-en">create_async_engine</span>(<span class="pl-s1">default_db</span>)
    <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-en">database_exists</span>(<span class="pl-s1">test_db</span>):  <span class="pl-c"># &lt;- Getting error on this line</span>
        <span class="pl-en">create_database</span>(<span class="pl-s1">test_db</span>)

    <span class="pl-v">Base</span>.<span class="pl-s1">metadata</span>.<span class="pl-en">create_all</span>(<span class="pl-s1">bind</span><span class="pl-c1">=</span><span class="pl-s1">engine</span>)
    <span class="pl-k">yield</span> <span class="pl-s1">engine</span>


<span class="pl-en">@<span class="pl-s1">pytest</span>.<span class="pl-en">fixture</span>(<span class="pl-s1">scope</span><span class="pl-c1">=</span><span class="pl-s">"function"</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">db</span>(<span class="pl-s1">db_engine</span>):
    <span class="pl-s1">connection</span> <span class="pl-c1">=</span> <span class="pl-s1">db_engine</span>.<span class="pl-en">connect</span>()

    <span class="pl-c"># begin a non-ORM transaction</span>
    <span class="pl-s1">connection</span>.<span class="pl-en">begin</span>()

    <span class="pl-c"># bind an individual Session to the connection</span>
    <span class="pl-v">Session</span> <span class="pl-c1">=</span> <span class="pl-en">sessionmaker</span>(<span class="pl-s1">bind</span><span class="pl-c1">=</span><span class="pl-s1">connection</span>)
    <span class="pl-s1">db</span> <span class="pl-c1">=</span> <span class="pl-v">Session</span>()
    <span class="pl-c"># db = Session(db_engine)</span>

    <span class="pl-k">yield</span> <span class="pl-s1">db</span>

    <span class="pl-s1">db</span>.<span class="pl-en">rollback</span>()
    <span class="pl-s1">connection</span>.<span class="pl-en">close</span>()


<span class="pl-en">@<span class="pl-s1">pytest</span>.<span class="pl-en">fixture</span>(<span class="pl-s1">scope</span><span class="pl-c1">=</span><span class="pl-s">"function"</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">client</span>(<span class="pl-s1">db</span>):
    <span class="pl-s1">app</span>.<span class="pl-s1">dependency_overrides</span>[<span class="pl-s1">get_session</span>] <span class="pl-c1">=</span> <span class="pl-k">lambda</span>: <span class="pl-s1">db</span>

    <span class="pl-v">PREFIX</span> <span class="pl-c1">=</span> <span class="pl-s">"/api/v1/my-endpoint"</span>
    <span class="pl-k">with</span> <span class="pl-v">TestClient</span>(<span class="pl-v">PREFIX</span>, <span class="pl-s1">app</span>) <span class="pl-k">as</span> <span class="pl-s1">c</span>:
        <span class="pl-k">yield</span> <span class="pl-s1">c</span></pre></div>
<p dir="auto">Here's the error I get:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="E                       sqlalchemy.exc.PendingRollbackError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: Task &lt;Task pending name='anyio.from_thread.BlockingPortal._call_func' coro=&lt;BlockingPortal._call_func() running at /usr/local/lib/python3.9/site-packages/anyio/from_thread.py:187&gt; cb=[TaskGroup._spawn.&lt;locals&gt;.task_done() at /usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py:629]&gt; got Future &lt;Future pending cb=[Protocol._on_waiter_completed()]&gt; attached to a different loop (Background on this error at: https://sqlalche.me/e/14/7s2a)

/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py:601: PendingRollbackError"><pre class="notranslate"><code class="notranslate">E                       sqlalchemy.exc.PendingRollbackError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: Task &lt;Task pending name='anyio.from_thread.BlockingPortal._call_func' coro=&lt;BlockingPortal._call_func() running at /usr/local/lib/python3.9/site-packages/anyio/from_thread.py:187&gt; cb=[TaskGroup._spawn.&lt;locals&gt;.task_done() at /usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py:629]&gt; got Future &lt;Future pending cb=[Protocol._on_waiter_completed()]&gt; attached to a different loop (Background on this error at: https://sqlalche.me/e/14/7s2a)

/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py:601: PendingRollbackError
</code></pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">I'm trying to create and drop test database during tests but I couldn't find any resources helping me do that. I posted to questions on StackOverflow (<a href="https://stackoverflow.com/questions/70752806/how-to-use-postgresql-test-database-in-async-fastapi-tests" rel="nofollow">this</a> and <a href="https://stackoverflow.com/questions/70798578/pendingrollbackerror-when-accessing-test-database-in-fastapi-async-test" rel="nofollow">this</a>) but got no answer. I believe this is a common use-case, so I figure I'd ask here. If this is possible, I believe an example of how to do it should be added to the documentation.</p>
<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.70.1</p>
<h3 dir="auto">Python Version</h3>
<p dir="auto">3.9.9</p>
<h3 dir="auto">Additional Context</h3>
<p dir="auto"><em>No response</em></p>