{"record":{"id":"9c83c8a0ebab88b5","repo":"pallets/flask","slug":"if-an-instance-path-is-provided-it-must-be-absolut","errorCode":null,"errorMessage":"If an instance path is provided it must be absolute. A relative path was given instead.","messagePattern":"If an instance path is provided it must be absolute\\. A relative path was given instead\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/flask/sansio/app.py","lineNumber":303,"sourceCode":"        host_matching: bool = False,\n        subdomain_matching: bool = False,\n        template_folder: str | os.PathLike[str] | None = \"templates\",\n        instance_path: str | None = None,\n        instance_relative_config: bool = False,\n        root_path: str | None = None,\n    ) -> None:\n        super().__init__(\n            import_name=import_name,\n            static_folder=static_folder,\n            static_url_path=static_url_path,\n            template_folder=template_folder,\n            root_path=root_path,\n        )\n\n        if instance_path is None:\n            instance_path = self.auto_find_instance_path()\n        elif not os.path.isabs(instance_path):\n            raise ValueError(\n                \"If an instance path is provided it must be absolute.\"\n                \" A relative path was given instead.\"\n            )\n\n        #: Holds the path to the instance folder.\n        #:\n        #: .. versionadded:: 0.8\n        self.instance_path = instance_path\n\n        #: The configuration dictionary as :class:`Config`.  This behaves\n        #: exactly like a regular dictionary but supports additional methods\n        #: to load a config from files.\n        self.config = self.make_config(instance_relative_config)\n\n        #: An instance of :attr:`aborter_class` created by\n        #: :meth:`make_aborter`. This is called by :func:`flask.abort`\n        #: to raise HTTP errors, and can be called directly as well.\n        #:","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/pallets/flask/blob/3596b1ab61cea85edb8970e83ff61daa073facf8/src/flask/sansio/app.py#L285-L321","documentation":"App.__init__ accepts an optional instance_path. If you supply one that is not absolute (os.path.isabs returns False), it raises ValueError. When instance_path is None Flask auto-discovers it; the explicit-value path strictly requires an absolute filesystem path because relative paths would be ambiguous depending on the process cwd.","triggerScenarios":"Constructing Flask(__name__, instance_path='instance') or Flask(__name__, instance_path='./instance')—any relative path. The check is elif not os.path.isabs(instance_path) on the non-None branch.","commonSituations":"Hardcoding a relative instance folder. Copying example code that used a relative path on a different OS. Assuming Flask resolves relative paths against the app root (it does not—it requires an absolute path or auto-detection).","solutions":["Pass an absolute path: Flask(__name__, instance_path='/abs/path/to/instance').","Omit instance_path entirely so Flask calls auto_find_instance_path() and derives it from root_path.","Build the absolute path from the app location: instance_path=os.path.join(os.path.dirname(__file__), 'instance') with abspath."],"exampleFix":"# before\napp = Flask(__name__, instance_path='instance')  # ValueError\n\n# after\napp = Flask(__name__)  # auto-find\n# or\napp = Flask(__name__, instance_path=os.path.abspath('instance'))","handlingStrategy":"validation","validationCode":"import os\n\ndef is_absolute_path(p: str) -> bool:\n    return os.path.isabs(p)","typeGuard":"import os\n\ndef is_absolute_path(p: str) -> bool:\n    return os.path.isabs(p)","tryCatchPattern":"import os\ntry:\n    app = Flask(__name__, instance_path=instance_path)\nexcept ValueError:\n    app = Flask(__name__, instance_path=os.path.abspath(instance_path))","preventionTips":["Pass instance_path as an absolute path or omit it for auto-detection.","Build instance paths with os.path.abspath(os.path.join(basedir, 'instance'))."],"tags":["flask","configuration","filesystem","paths"],"backgroundTag":null,"analyzedSha":"3596b1ab61cea85edb8970e83ff61daa073facf8","analyzedAt":"2026-08-11T20:11:52.622Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}