This repository was archived by the owner on Apr 15, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 92
Field's named 'models' cause issues with resolving pydantic models. #1067
Copy link
Copy link
Open
Description
Bug description
Given a schema
datasource db {
provider = "sqlite"
url = "file:./dev.db"
}
generator py {
provider = "prisma-client-py"
}
model A {
id Int @id @default(autoincrement())
B B @relation(fields: [bId], references: [id])
bId Int
}
model B {
id Int @id @default(autoincrement())
models A[]
}When importing the generated client an error is thrown
eval(self.__forward_code__, globalns, localns),
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'A'
I suspect because the 'models' field name is clashing with the models namespace for the pydantic models. Removing the namespace in the client and referring directly to the prisma model allows the import to work
e.g from
class B(bases.BaseB):
"""Represents a B record"""
id: _int
models: Optional[List['models.A']] = Noneto
class B(bases.BaseB):
"""Represents a B record"""
id: _int
models: Optional[List['A']] = NoneHow to reproduce
Create the above schema as prisma.schema
uv init
uv add prisma
uv run python -m prisma generate --schema prisma.schema
uv run python -c 'import prisma'
Expected behavior
The client to be able to import and retain a field called 'models' on B
Prisma information
see above
Environment & setup
- OS: Mac
- Database: MySQL also tested with SQLite
- Python version: Python 3.10.0, also tested with 3.11 and 3.13
- Prisma version:
prisma : 5.17.0
prisma client python : 0.15.0
platform : darwin
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels