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.

Cannot use field named "fields" and field with type Json in the same model if there is a model named "Fields" #1065

@jcassee

Description

@jcassee

Bug description

When these three conditions are present, importing prisma will generate an error:

  • A model exists which is named Field.
  • Another model exists with a Json typed field.
  • This second model has a field name fields referring to a list of Fields.

In this case, when Pydantic resolves the reference, the model fields are in the local namespace. This causes fields to match the model field instead of the fields module that contains the Json field type.

This is the resulting error:

[...]
  File "[...]/python/3.10.13/lib/python3.10/typing.py", line 695, in _evaluate
    eval(self.__forward_code__, globalns, localns),
  File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'Json'

How to reproduce

  1. Generate Python code for the Prisma schema below.
  2. Import the prisma package.
  3. The stack trace is printed.

Expected behavior

The prisma package should be loaded, no output.

Prisma information

generator client {
  provider             = "prisma-client-py"
  recursive_type_depth = 5
}

datasource db {
  provider   = "postgresql"
  url        = env("DATABASE_URL")
}

model Demo {
  id         Int    @id @default(autoincrement())
  demo_field Json   @default("{}")
  fields     Field[]
}

model Field {
  id      Int  @id @default(autoincrement())
  demo    Demo @relation(fields: [demo_id], references: [id])
  demo_id Int
}

Environment & setup

  • OS: Arch Linux
  • Database: PostgreSQL
  • Python version: Python 3.13.1
  • Prisma version:
prisma                  : 5.17.0
prisma client python    : 0.15.0
platform                : debian-openssl-3.4.x
expected engine version : 393aa359c9ad4a4bb28630fb5613f9c281cde053
installed extras        : []
install path            : [...]/.venv/lib/python3.13/site-packages/prisma
binary cache dir        : [...]/.cache/prisma-python/binaries/5.17.0/393aa359c9ad4a4bb28630fb5613f9c281cde053

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