Limitations
Type Limitations
Note
It is highly recommended to use pyright as your type checker of choice for Prisma Client Python applications.
Due to mypy limtations, some types are not as explicit as they should be and as such cannot be considered fully type safe, however all of the limitations imposed by mypy can be removed by switching to pyright and configuring prisma to use recursive types.
Removing Limitations
You can catch all errors while type checking by using pyright and configuring prisma to use recursive types.
Querying Using Model-based Access
Prisma Client Python supports querying directly from model classes, however, internally typing this feature with generics causes mypy to be incredibly slow, it takes upwards of 35 minutes to type check the Prisma Client Python codebase on CI and upwards of 2 hours locally.
This kind of performance is not acceptable and as such, prisma models cannot be subclassed by default.
Trying to subclass a prisma model will raise an error at runtime.
from prisma.models import User
class MyUser(User):
pass
Filtering by Relational Fields
Prisma supports searching for records based off of relational record values. However, type checking this feature with mypy casued mypy to hang and eventually crash.
As such these types have been broadened, this means that mypy will not catch errors when filtering by a relational field, for example, the following will not raise any mypy errors, however an error will be raised at runtime.
from prisma import Client
async def main(client: Client) -> None:
user = await client.user.find_first(
where={
'profile': {
'is': {
'an_invalid_value': 'foo',
},
},
}
)