Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Field's named 'models' cause issues with resolving pydantic models. #1067

@sammaxwellxyz

Description

@sammaxwellxyz

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']] = None

to

class B(bases.BaseB):
    """Represents a B record"""

    id: _int
    models: Optional[List['A']] = None

How 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions