{"id":"a963119d0c6d6b9e","repo":"aio-libs/aiohttp","slug":"the-first-argument-should-be-web-application-insta","errorCode":null,"errorMessage":"The first argument should be web.Application instance, got {app!r}","messagePattern":"The first argument should be web\\.Application instance, got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"aiohttp/web_runner.py","lineNumber":440,"sourceCode":"    async def _cleanup_server(self) -> None:\n        pass\n\n\nclass AppRunner(BaseRunner[Request]):\n    \"\"\"Web Application runner\"\"\"\n\n    __slots__ = (\"_app\",)\n\n    def __init__(\n        self,\n        app: Application,\n        *,\n        handle_signals: bool = False,\n        access_log_class: type[AbstractAccessLogger] = AccessLogger,\n        **kwargs: Any,\n    ) -> None:\n        if not isinstance(app, Application):\n            raise TypeError(\n                f\"The first argument should be web.Application instance, got {app!r}\"\n            )\n        kwargs[\"access_log_class\"] = access_log_class\n\n        if app._handler_args:\n            for k, v in app._handler_args.items():\n                kwargs[k] = v\n\n        if not issubclass(kwargs[\"access_log_class\"], AbstractAccessLogger):\n            raise TypeError(\n                \"access_log_class must be subclass of \"\n                \"aiohttp.abc.AbstractAccessLogger, got {}\".format(\n                    kwargs[\"access_log_class\"]\n                )\n            )\n\n        super().__init__(handle_signals=handle_signals, **kwargs)\n        self._app = app","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/web_runner.py#L422-L458","documentation":"Raised as TypeError by AppRunner.__init__ when the first positional argument is not an instance of aiohttp.web.Application. The runner needs a real Application to bind its request factory, startup/shutdown signals, and frozen router, so a non-Application object (a router, a dict, None, an Application subclass instance that failed import, etc.) cannot be accepted. The check happens before any server wiring, so it fails fast at construction time.","triggerScenarios":"Calling aiohttp.web.AppRunner(some_object) where some_object is not an Application — e.g. passing a Router, a raw coroutine, a port number, or None. Also triggered by passing an Application from a different aiohttp install whose class identity differs (isinstance fails across module re-imports).","commonSituations":"Confusing AppRunner with web.AppRunner usage in tutorials; passing app.router instead of app; passing the handler coroutine instead of the app; virtualenv/conda mixing two aiohttp versions so isinstance(app, Application) is False; partially-initialized app from a factory that returned None.","solutions":["Pass the actual aiohttp.web.Application instance: AppRunner(app) where app = web.Application().","If using an app factory, call it first: app = await factory(); runner = web.AppRunner(app).","Ensure only one aiohttp version is installed (pip show aiohttp, resolve duplicate installs) so isinstance identity holds.","Check for None returns from your app builder before constructing the runner."],"exampleFix":"# before\nrunner = web.AppRunner(app.router)\n\n# after\nrunner = web.AppRunner(app)","handlingStrategy":"type-guard","validationCode":"from aiohttp import web\n\ndef make_runner(app):\n    assert isinstance(app, web.Application), f\"expected Application, got {type(app)}\"\n    return web.AppRunner(app)","typeGuard":"from aiohttp import web\nimport aiohttp.web as webmod\n\ndef is_application(app) -> bool:\n    return isinstance(app, webmod.Application)","tryCatchPattern":"try:\n    runner = web.AppRunner(app)\nexcept TypeError as e:\n    raise SystemExit(f\"Invalid app passed to AppRunner: {e}\") from e","preventionTips":["Type-annotate app factories -> Application and assert the return before passing to AppRunner.","Resolve duplicate aiohttp installs before deploying.","Unit-test runner construction with a real Application instance."],"tags":["aiohttp","web-server","type-error","app-runner","startup"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}