{"record":{"id":"687012b4df6d973e","repo":"invoke-ai/InvokeAI","slug":"not-a-valid-file-or-directory-model-path","errorCode":null,"errorMessage":"Not a valid file or directory: {model_path}","messagePattern":"Not a valid file or directory: (.+?)","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/model_hash/model_hash.py","lineNumber":109,"sourceCode":"            str: Hexdigest of the hash of the model\n        \"\"\"\n\n        model_path = Path(model_path)\n        # blake3_single is a single-threaded version of blake3, prefix should still be \"blake3:\"\n        prefix = self._get_prefix(self.algorithm)\n        if model_path.is_file():\n            hash_ = None\n            # To give a similar user experience for single files and directories, we use a progress bar even for single files\n            pbar = tqdm([model_path], desc=f\"Hashing {model_path.name}\", unit=\"file\")\n            for component in pbar:\n                pbar.set_description(f\"Hashing {component.name}\")\n                hash_ = prefix + self._hash_file(model_path)\n            assert hash_ is not None\n            return hash_\n        elif model_path.is_dir():\n            return prefix + self._hash_dir(model_path)\n        else:\n            raise OSError(f\"Not a valid file or directory: {model_path}\")\n\n    def _hash_dir(self, dir: Path) -> str:\n        \"\"\"Compute the hash for all files in a directory and return a hexdigest.\n\n        Args:\n            dir: Path to the directory\n\n        Returns:\n            str: Hexdigest of the hash of the directory\n        \"\"\"\n        model_component_paths = self._get_file_paths(dir, self._file_filter)\n\n        component_hashes: list[str] = []\n        pbar = tqdm(sorted(model_component_paths), desc=f\"Hashing {dir.name}\", unit=\"file\")\n        for component in pbar:\n            pbar.set_description(f\"Hashing {component.name}\")\n            component_hashes.append(self._hash_file(component))\n","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/model_hash/model_hash.py#L91-L127","documentation":"ModelHash.hash raises OSError when the given path is neither an existing file nor an existing directory. The method dispatches on is_file()/is_dir() and falls through to this error when both checks fail.","triggerScenarios":"Calling hasher.hash(model_path) with a non-existent path, a deleted model directory, a broken symlink, a dangling mount, or a Path containing a typo / wrong case.","commonSituations":"Model was moved or deleted after registration in the DB; autoimport scan directories removed; path built with wrong base (relative vs absolute); network mount not mounted when hashing.","solutions":["Verify the path exists: Path(model_path).exists() before calling hash().","Fix the path typo or rebuild it from the model config's actual location.","Re-point the model record to the new location if the model was moved, or re-register/re-scan the model folder.","Check mounts/permissions if the path should exist (broken symlink or missing mount)."],"exampleFix":"// before\nh = hasher.hash('/models/typo-name.safetensors')  # OSError\n// after\np = Path('/models/real-name.safetensors')\nassert p.exists(), f'missing: {p}'\nh = hasher.hash(p)","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef path_is_hashable(model_path: str | Path) -> bool:\n    p = Path(model_path)\n    return p.is_file() or p.is_dir()","typeGuard":"def is_existing_path(p: object) -> TypeGuard[Path]:\n    return isinstance(p, Path) and (p.is_file() or p.is_dir())","tryCatchPattern":"try:\n    digest = hasher.hash(model_path)\nexcept OSError as e:\n    logger.error(f'Model path missing or invalid: {e}')\n    raise ModelNotFoundError(model_path) from e","preventionTips":["Check Path(model_path).exists() before hashing or registering a model.","Keep model records and the filesystem in sync - re-scan after moving/deleting models.","Use absolute paths and resolve symlinks before storing them."],"tags":["invokeai","filesystem","path","hash"],"backgroundTag":"file-not-found","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}