Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jcassee opened this issue Feb 20, 2025 · 0 comments

Comments

@jcassee
Copy link

jcassee commented Feb 20, 2025

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant