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

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

Closed
FlorianVenturini opened this issue Nov 30, 2022 · 6 comments
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client.

Comments

@FlorianVenturini
Copy link

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
@FlorianVenturini FlorianVenturini added the kind/bug A reported bug. label Nov 30, 2022
@nowlena
Copy link

nowlena commented Nov 30, 2022

I had the exact same issue and had to roll back to an older Prisma version.

  • I was sure to clear all old Prisma files out and run a new "db push" and "generate" when trying to update (another issue said this was the problem)

Environment & setup

  • OS: Windows 11 (WSL2 Ubuntu 22.04)
  • Database: MySQL (via PlanetScale)
  • Node.js version: v16.17.0

@SevInf SevInf added kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. labels Nov 30, 2022
@SevInf
Copy link
Contributor

SevInf commented Nov 30, 2022

Duplicate of #16548

@SevInf SevInf marked this as a duplicate of #16548 Nov 30, 2022
@SevInf SevInf closed this as completed Nov 30, 2022
@miguelff miguelff added the bug/2-confirmed Bug has been reproduced and confirmed. label Nov 30, 2022
@miguelff
Copy link
Contributor

miguelff commented 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.

@SevInf SevInf changed the title "Field does not exist on enclosing type" (4.7.0 findUniqueOrThrow) "Field does not exist on enclosing type" error is thrown in findUniqueOrThrow Dec 1, 2022
@focux
Copy link

focux commented Dec 1, 2022

Any idea when this fix is going to be released?

@janpio
Copy link
Member

janpio commented Dec 1, 2022

Most probably tomorrow morning.

@SevInf
Copy link
Contributor

SevInf commented Dec 2, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client.
Projects
None yet
Development

No branches or pull requests

6 participants