{"record":{"id":"90821d20c3adf395","repo":"pytest-dev/pytest","slug":"name-is-not-allowed-to-contain-path-separators","errorCode":null,"errorMessage":"name is not allowed to contain path separators","messagePattern":"name is not allowed to contain path separators","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/_pytest/cacheprovider.py","lineNumber":179,"sourceCode":"        path.mkdir(exist_ok=True, parents=True)\n\n    def mkdir(self, name: str) -> Path:\n        \"\"\"Return a directory path object with the given name.\n\n        If the directory does not yet exist, it will be created. You can use\n        it to manage files to e.g. store/retrieve database dumps across test\n        sessions.\n\n        .. versionadded:: 7.0\n\n        :param name:\n            Must be a string not containing a ``/`` separator.\n            Make sure the name contains your plugin or application\n            identifiers to prevent clashes with other cache users.\n        \"\"\"\n        path = Path(name)\n        if len(path.parts) > 1:\n            raise ValueError(\"name is not allowed to contain path separators\")\n        res = self._cachedir.joinpath(self._CACHE_PREFIX_DIRS, path)\n        self._mkdir(res)\n        return res\n\n    def _getvaluepath(self, key: str) -> Path:\n        return self._cachedir.joinpath(self._CACHE_PREFIX_VALUES, Path(key))\n\n    def get(self, key: str, default):\n        \"\"\"Return the cached value for the given key.\n\n        If no value was yet cached or the value cannot be read, the specified\n        default is returned.\n\n        :param key:\n            Must be a ``/`` separated value. Usually the first\n            name is the name of your plugin or your application.\n        :param default:\n            The value to return in case of a cache-miss or invalid cache value.","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/cacheprovider.py#L161-L197","documentation":"Raised by Cache.mkdir() when the supplied name contains a path separator, detected by Path(name) having more than one part. The cache API is designed for flat, single-segment namespaced keys to prevent path traversal and arbitrary directory creation under the cache root. Names must be a single path component.","triggerScenarios":"request.config.cache.mkdir('myplugin/subdir') (contains '/'); cache.mkdir('a\\b') on Windows; passing a composite key intended for a hierarchy.","commonSituations":"Treating the cache key like a filesystem path; attempting to nest cache directories; porting code that joined segments with os.sep.","solutions":["Use a single flat name: cache.mkdir('myplugin_subdir').","Encode hierarchy in the name with a safe delimiter that is not a path separator (e.g. '__').","If you need nested dirs, manage them outside the cache API via pathlib."],"exampleFix":"// before\nrequest.config.cache.mkdir('myplugin/data')\n// after\nrequest.config.cache.mkdir('myplugin__data')","handlingStrategy":"validation","validationCode":"from pathlib import Path\ndef safe_cache_mkdir(cache, name):\n    if len(Path(name).parts) > 1:\n        name = name.replace('/', '__').replace('\\\\', '__')\n    return cache.mkdir(name)","typeGuard":"from pathlib import Path\ndef is_flat_name(name: str) -> bool:\n    return len(Path(name).parts) <= 1","tryCatchPattern":null,"preventionTips":["Use single-segment names for cache keys.","Encode hierarchy with '__' or ':' delimiters, never path separators."],"tags":["cache","cacheprovider","path-validation","security"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}