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

prisma.errors.FieldNotFoundError Error when creating item with nested item. #965

Open
Bewinxed opened this issue May 29, 2024 · 1 comment

Comments

@Bewinxed
Copy link

Bewinxed commented May 29, 2024

Bug description

I have a db with the schema mentioned, suddenly on one of the tables, I can't seem to insert a value like below, I made sure to run prisma generate + prisma db push.

The field is indeed in my database table

How to reproduce

await db.personaemotion.create(
            data={
                "outfit_id": str(outfit_id),
                "appearance_id": str(appearance_id),
                "name": emotion,
                "description": emotion_prompt.choices[0].message.content,
                "image": {
                    "create": {
                        "id": str(image_id),
                        "persona_id": str(persona_id),
                        "persona_appearance_id": str(appearance_id),
                        "meta": Json(res.parameters),
                        "mime_type": "image/png",
                        "extension": "png",
                        "type": Mediatypes.IMAGE,
                    },
                },
            },
        )

ERROR

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 411, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/middleware/cors.py", line 85, in __call__
    await self.app(scope, receive, send)
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 297, in handle
    await self.app(scope, receive, send)
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 77, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/starlette/routing.py", line 72, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 278, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bewinxed/Development/eve-backend/backend/routes/api/users/[user_id]/personas/[persona_id]/appearances/[appearance_id]/outfits/[outfit_id]/generate/route.py", line 254, in generate_image
    await db.personaemotion.create(
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/prisma/actions.py", line 16630, in create
    resp = await self._client._execute(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/prisma/_base_client.py", line 533, in _execute
    return await self._engine.query(builder.build(), tx_id=self._tx_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/prisma/engine/_query.py", line 404, in query
    return await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/prisma/engine/_http.py", line 233, in request
    return self._process_response_data(data=data, response=response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/prisma/engine/_http.py", line 87, in _process_response_data
    return utils.handle_response_errors(response, errors_data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/prisma/engine/utils.py", line 175, in handle_response_errors
    raise exc(error)
prisma.errors.FieldNotFoundError: Could not find field at `createOnePersonaEmotion.data.appearance_id`

Expected behavior

Prisma information

model PersonaEmotion {
  id String @id @default(uuid()) @db.Uuid

  outfit_id     String? @db.Uuid
  appearance_id String? @db.Uuid

  //
  name        String
  description String?
  image_id    String?   @db.Uuid
  image       Document? @relation(fields: [image_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
  // timestamps
  created_at  DateTime? @default(dbgenerated("now()"))
  updated_at  DateTime? @default(dbgenerated("now()")) @updatedAt

  // relations
  outfits               PersonaOutfit?       @relation(fields: [outfit_id], references: [id])
  appearance            PersonaAppearance?   @relation(fields: [appearance_id], references: [id])

  @@index([name], map: "ix_persona_emotion_name")
}

model PersonaOutfit {
  id String @id @default(uuid()) @db.Uuid

  //
  persona_id    String  @db.Uuid
  appearance_id String? @db.Uuid
  prompt_id     String? @db.Uuid

  //
  name        String
  description String?

  //
  image_id  String? @db.Uuid
  avatar_id String? @db.Uuid

  // timestamps
  created_at DateTime @default(dbgenerated("now()"))
  updated_at DateTime @default(dbgenerated("now()")) @updatedAt

  // relations
  persona    Persona            @relation(fields: [persona_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
  appearance PersonaAppearance? @relation(fields: [appearance_id], references: [id], onDelete: Cascade, onUpdate: Cascade)

  prompt   Prompt?          @relation(fields: [prompt_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
  emotions PersonaEmotion[]

  image  Document? @relation("outfitImage", fields: [image_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
  avatar Document? @relation("outfitAvatar", fields: [avatar_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
}

model PersonaAppearance {
  id String @id @default(uuid()) @db.Uuid

  //
  persona_id String  @db.Uuid
  prompt_id  String? @db.Uuid

  //
  name        String
  description String?

  // 

  image_id  String? @db.Uuid
  avatar_id String? @db.Uuid

  // timestamps
  created_at DateTime @default(dbgenerated("now()"))
  updated_at DateTime @default(dbgenerated("now()")) @updatedAt

  // relations
  persona              Persona              @relation(fields: [persona_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
  prompt               Prompt?              @relation(fields: [prompt_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
  outfits              PersonaOutfit[]
  emotions             PersonaEmotion[]
  training_images      Document[]

  image  Document? @relation("appearanceImage", fields: [image_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
  avatar Document? @relation("appearanceAvatar", fields: [avatar_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
}

model Document {
  id String @id @default(uuid()) @db.Uuid

  //
  user_id         String?    @db.Uuid
  persona_id      String?    @db.Uuid
  organization_id String?    @db.Uuid
  project_id      String?    @db.Uuid
  // 
  media_id        String?
  thumbnail_id    String?    @db.Uuid
  platform        String?
  url             String?
  filename        String?
  type            Mediatypes
  mime_type       String
  extension       String?
  status          String?
  meta            Json?
  hash            String?
  error           String?

  // timestamps
  created_at DateTime @default(dbgenerated("now()"))
  updated_at DateTime @default(dbgenerated("now()")) @updatedAt

  // relations
  organization     Organization?      @relation(fields: [organization_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
  persona          Persona?           @relation(fields: [persona_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
  project          Project?           @relation(fields: [project_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
  document         Document?          @relation("documentTodocument", fields: [thumbnail_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
  other_documents  Document[]         @relation("documentTodocument")
  user             User?              @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
  nodes            Node[]
  PersonaEmotion   PersonaEmotion[]

  image_persona  Persona[] @relation("personaAvatar")
  avatar_persona Persona[] @relation("personaImage")

  image_appearance  PersonaAppearance[] @relation("appearanceImage")
  avatar_appearance PersonaAppearance[] @relation("appearanceAvatar")

  image_outfit        PersonaOutfit[]    @relation("outfitImage")
  avatar_outfit       PersonaOutfit[]    @relation("outfitAvatar")
  persona_appearance   PersonaAppearance? @relation(fields: [persona_appearance_id], references: [id])
  persona_appearance_id String?            @db.Uuid @map("personaAppearanceId")
}

Environment & setup

  • OS:
  • Database:
  • Python version:
  • Prisma version:
prisma                  : 5.11.0
prisma client python    : 0.13.1
platform                : darwin
expected engine version : efd2449663b3d73d637ea1fd226bafbcf45b3102
installed extras        : []
install path            : /Users/bewinxed/Development/eve-backend/.venv/lib/python3.12/site-packages/prisma
binary cache dir        : /Users/bewinxed/.cache/prisma-python/binaries/5.11.0/efd2449663b3d73d637ea1fd226bafbcf45b3102
@krrishdholakia
Copy link

facing a similar issue

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

2 participants