question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Field does not exist on enclosing type" error is thrown in `findUniqueOrThrow`

See original GitHub issue

Bug description

Hello! I updated prisma from 4.6.1 to 4.7.0 and when testing my code sent me this error message:

`Field does not exist on enclosing type.` at `Query.findManyPostOrThrow`

How to reproduce

main.ts:

import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

const id1 = 'VALID_ID1';
const id2 = 'VALID_ID2';

async function setup(): Promise<void> {
  // 1. Clear DB
  console.log('DeleteMany:', await prisma.post.deleteMany());

  // 2. Add posts
  console.log('\nCreate posts:', await prisma.post.createMany({
    data: [
      {
        id: id1,
        title: 'New post',
      },
      {
        id: id2,
        title: 'New post 2!',
      }
    ],
  }));
}

async function find(id: string): Promise<void> {
  // 1. Query it with findUnique (no error)
  console.log('\nFindUnique:', await prisma.post.findUnique({
    where: { id },
  }));

  // 2. Query it with findUniqueOrThrow (crash??)
  console.log('\nFindUniqueOrThrow:', await prisma.post.findUniqueOrThrow({
    where: { id },
  }));
}

async function main(): Promise<void> {
  await setup();
  await Promise.all([id1, id2].map(find));
}

main().then(() => console.log('OK!')).catch((err) => console.error(err));

prisma/schema.prisma:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["extendedWhereUnique"]
}

datasource db {
  provider = "postgresql"
  url      = "postgresql://test:testPassword123@localhost:5434/test?schema=public"
}

model Post {
  id        String   @id
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  title String

  @@map("posts")
}

docker-compose.yml:

version: '3.8'

services:
  db_test:
    container_name: db_test
    image: postgres:13.6
    restart: always
    environment:
      POSTGRES_USER: test
      POSTGRES_PASSWORD: testPassword123
    ports:
      - 5434:5432

package.json:

{
  "scripts": {
    "test": "ts-node main"
  },
  "devDependencies": {
    "prisma": "^4.7.0",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.3"
  },
  "dependencies": {
    "@prisma/client": "^4.7.0"
  }
}

Run the following commands:

docker compose up -d
npm install
npx prisma migrate dev --name add
npm run test

Expected behavior

It should not crash

Prisma information

see above

Environment & setup

  • OS: macOS Ventura 13.0
  • Database: PostgresQL
  • Node.js version: 18.12.1

Prisma Version

prisma                  : 4.7.0
@prisma/client          : 4.7.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 39190b250ebc338586e25e6da45e5e783bc8a635 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 39190b250ebc338586e25e6da45e5e783bc8a635 (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core 39190b250ebc338586e25e6da45e5e783bc8a635 (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt 39190b250ebc338586e25e6da45e5e783bc8a635 (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.7.0-74.39190b250ebc338586e25e6da45e5e783bc8a635
Default Engines Hash    : 39190b250ebc338586e25e6da45e5e783bc8a635
Studio                  : 0.477.0
Preview Features        : extendedWhereUnique

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
miguelffcommented, Nov 30, 2022

There’s indeed a bug in the way findUniqueOrThrow is being batched. We identified the root cause, and we are working towards resolution.

1reaction
SevInfcommented, Dec 2, 2022

4.7.1 is released and it contains the fix for this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Field does not exist on enclosing type" when trying to create a ...
getting this error: Failed to validate the query: `Field does not exist on enclosing type.` at `Mutation.createOnevideos` at cb (.
Read more >
Prisma client breaks when I add a field to a model
I assume the Prisma error message (“Field does not exist on enclosing type”) means that Prisma thinks there isn't an avatarCode field on...
Read more >
Prisma 4.7.1 Release - GitClear
Today, we are issuing the 4.7.1 patch release. Fixes in Prisma Client. Enum fields are missing in select's type when clientExtensions preview ...
Read more >
type-graphql/prisma2 - Gitter
Hey, I get a following error when im trying to generate ts classes using prisma generate . Error: Unexpected! ... Field does not...
Read more >
prisma findUnique where takes only one unique argument
I am not entirely certain, but prisma returns a JS object. ... Logically speaking, the email is a unique field (there won't be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found