crewAIInc/crewAI · error · TypeError
{type(source).__name__} does not support async read
Error message
{type(source).__name__} does not support async read What it means
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.
Source
Thrown at lib/crewai-files/src/crewai_files/core/types.py:212
@property
def content_type(self) -> str:
"""Get the content type from the source."""
return self._file_source.content_type
def read(self) -> bytes:
"""Read the file content as bytes."""
return self._file_source.read() # type: ignore[union-attr]
async def aread(self) -> bytes:
"""Async read the file content as bytes.
Raises:
TypeError: If the underlying source doesn't support async read.
"""
source = self._file_source
if isinstance(source, (FilePath, FileBytes, AsyncFileStream, FileUrl)):
return await source.aread()
raise TypeError(f"{type(source).__name__} does not support async read")
def read_text(self, encoding: str = "utf-8") -> str:
"""Read the file content as string."""
return self.read().decode(encoding)
@property
def _unpack_key(self) -> str:
"""Get the key to use when unpacking (filename stem)."""
filename = self._file_source.filename
if filename:
return Path(filename).stem
return "file"
def keys(self) -> list[str]:
"""Return keys for dict unpacking."""
return [self._unpack_key]
def __getitem__(self, key: str) -> Self:View on GitHub (pinned to 754d7323be)
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.
Example fix
# before data = await file.aread() # TypeError: FileStream does not support async read # after import asyncio data = await asyncio.to_thread(file.read)
Defensive patterns
Strategy: type-guard
Validate before calling
from crewai_files.core.sources import FilePath, FileBytes, AsyncFileStream, FileUrl
def supports_aread(source) -> bool:
return isinstance(source, (FilePath, FileBytes, AsyncFileStream, FileUrl)) Type guard
import asyncio
from crewai_files.core.sources import FilePath, FileBytes, AsyncFileStream, FileUrl
async def read_any(file) -> bytes:
src = file._file_source
if isinstance(src, (FilePath, FileBytes, AsyncFileStream, FileUrl)):
return await file.aread()
return await asyncio.to_thread(file.read) Try / catch
try:
data = await file.aread()
except TypeError as e:
if "does not support async read" in str(e):
data = await asyncio.to_thread(file.read) Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Expected an async readable object with async read() method
- Cannot convert {type(v).__name__} to file source
- Expected a binary file-like object with read() and seek()
- Path traversal not allowed: {self.path}
- Symlink escapes allowed directory: {self.path}
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/5fddf6bb9e39efe7.
Report an issue: GitHub.