{"record":{"id":"5fddf6bb9e39efe7","repo":"crewAIInc/crewAI","slug":"type-source-name-does-not-support-async-rea","errorCode":null,"errorMessage":"{type(source).__name__} does not support async read","messagePattern":"(.+?) does not support async read","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/crewai-files/src/crewai_files/core/types.py","lineNumber":212,"sourceCode":"    @property\n    def content_type(self) -> str:\n        \"\"\"Get the content type from the source.\"\"\"\n        return self._file_source.content_type\n\n    def read(self) -> bytes:\n        \"\"\"Read the file content as bytes.\"\"\"\n        return self._file_source.read()  # type: ignore[union-attr]\n\n    async def aread(self) -> bytes:\n        \"\"\"Async read the file content as bytes.\n\n        Raises:\n            TypeError: If the underlying source doesn't support async read.\n        \"\"\"\n        source = self._file_source\n        if isinstance(source, (FilePath, FileBytes, AsyncFileStream, FileUrl)):\n            return await source.aread()\n        raise TypeError(f\"{type(source).__name__} does not support async read\")\n\n    def read_text(self, encoding: str = \"utf-8\") -> str:\n        \"\"\"Read the file content as string.\"\"\"\n        return self.read().decode(encoding)\n\n    @property\n    def _unpack_key(self) -> str:\n        \"\"\"Get the key to use when unpacking (filename stem).\"\"\"\n        filename = self._file_source.filename\n        if filename:\n            return Path(filename).stem\n        return \"file\"\n\n    def keys(self) -> list[str]:\n        \"\"\"Return keys for dict unpacking.\"\"\"\n        return [self._unpack_key]\n\n    def __getitem__(self, key: str) -> Self:","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-files/src/crewai_files/core/types.py#L194-L230","documentation":"Raised by File.aread() when the wrapped _file_source supports sync read but not async: only FilePath, FileBytes, AsyncFileStream, and FileUrl implement aread(). A FileStream (sync binary stream) does not, so calling aread() on a File backed by one raises TypeError naming the source class. This is an API-surface mismatch: use read() for sync sources.","triggerScenarios":"File(source=FileStream(stream=open('x.pdf','rb'))).aread(); likewise FileBytes? no — FileBytes supports aread; concretely any File whose source is a FileStream, then calling .aread() (e.g. inside an async handler).","commonSituations":"Codebases that uniformly call aread() in async endpoints but receive sync FileStream objects from callers/tests; adapters that wrap sync uploads as FileStream and later get awaited.","solutions":["Use read() (optionally via asyncio.to_thread / run_in_executor) for sync FileStream-backed Files.","If you control construction, load the content eagerly into FileBytes so aread() works.","Branch on the source type or catch TypeError and fall back to the thread-offloaded sync read."],"exampleFix":"# before\ndata = await file.aread()  # TypeError: FileStream does not support async read\n\n# after\nimport asyncio\ndata = await asyncio.to_thread(file.read)","handlingStrategy":"type-guard","validationCode":"from crewai_files.core.sources import FilePath, FileBytes, AsyncFileStream, FileUrl\n\ndef supports_aread(source) -> bool:\n    return isinstance(source, (FilePath, FileBytes, AsyncFileStream, FileUrl))","typeGuard":"import asyncio\nfrom crewai_files.core.sources import FilePath, FileBytes, AsyncFileStream, FileUrl\n\nasync def read_any(file) -> bytes:\n    src = file._file_source\n    if isinstance(src, (FilePath, FileBytes, AsyncFileStream, FileUrl)):\n        return await file.aread()\n    return await asyncio.to_thread(file.read)","tryCatchPattern":"try:\n    data = await file.aread()\nexcept TypeError as e:\n    if \"does not support async read\" in str(e):\n        data = await asyncio.to_thread(file.read)","preventionTips":["Standardize on a read_any helper that falls back to to_thread for sync sources.","When you control construction, prefer FileBytes so both read() and aread() work."],"tags":["async","file-sources","api-mismatch"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}