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

jsonProtocol Field/Enum is not included in the result of the findFirst/findMany function #18200

Closed
AntoineBW opened this issue Mar 3, 2023 · 5 comments · Fixed by prisma/prisma-engines#3764
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: enum "type"/block `enum` topic: jsonProtocol
Milestone

Comments

@AntoineBW
Copy link

Bug description

Hi, regarding the jsonProtocol (#18095) as a preview feature, there is a bug where an enum is not included during a findMany or a findFirst.

How to reproduce

npx prisma db push --force-reset
node ./app.js

{
  bugFirst: { id: 1 },
  bugMany: [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ],
  noBugFirst: { id: 1, asset: 'A' },
  noBugMany: [
    { id: 1, asset: 'A' },
    { id: 2, asset: 'B' },
    { id: 3, asset: 'C' },
    { id: 4, asset: 'D' }
  ]
}

Expected behavior

Bug: The field/enum "asset" is not included in the result of the findFirst/findMany function when the select is empty by default

Prisma information

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

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

enum ExampleEnum {
  A
  B
  C
  D
}

model Example {
  id    Int         @id @default(autoincrement())
  asset ExampleEnum
}

app.js

import { ExampleEnum, PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();

// Init/Seed
await prisma.example.deleteMany();
await prisma.example.createMany({ data: [{ asset: ExampleEnum.A }, { asset: ExampleEnum.B }, { asset: ExampleEnum.C }, { asset: ExampleEnum.D }] });

// Bug
const bugFirst = await prisma.example.findFirst();
const bugMany = await prisma.example.findMany();

// No bug
const noBugFirst = await prisma.example.findFirst({ select: { id: true, asset: true } });
const noBugMany = await prisma.example.findMany({ select: { id: true, asset: true } });
console.log({ bugFirst, bugMany, noBugFirst, noBugMany });

Environment & setup

  • OS: Windows
  • Database: PostgreSQL
  • Node.js version: v18.12.1

Prisma Version

prisma                  : 4.11.0
@prisma/client          : 4.11.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine 8fde8fef4033376662cad983758335009d522acb (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli 8fde8fef4033376662cad983758335009d522acb (at node_modules\@prisma\engines\migration-engine-windows.exe)
Format Wasm             : @prisma/prisma-fmt-wasm 4.11.0-57.8fde8fef4033376662cad983758335009d522acb
Default Engines Hash    : 8fde8fef4033376662cad983758335009d522acb
Studio                  : 0.483.0
Preview Features        : jsonProtocol
@AntoineBW AntoineBW added the kind/bug A reported bug. label Mar 3, 2023
@veiico
Copy link

veiico commented Mar 3, 2023

can confirm, same issue, all the places that used enums were retrieved as undefined

@janpio
Copy link
Member

janpio commented Mar 3, 2023

We already fixed some enum related bugs, can you maybe try with prisma@dev and @prisma/client@dev? Maybe this is already fixed. Thanks.

@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. team/client Issue for team Client. labels Mar 3, 2023
@revmischa
Copy link

prisma@dev does fix the enum being undefined
However arrays of enums are undefined:

model User {
  id        String    @id @default(dbgenerated("uuid_generate_v4()")) @map("id") @db.Uuid
  createdAt DateTime  @default(now()) @map("created_at") @db.Timestamptz
  deletedAt DateTime? @map("deleted_at") @db.Timestamptz

  roles     UserRoles[] // Role that can be assigned to user (for example admin, interviewer, etc)
}

Previously, user.roles would return [] but with jsonProtocol it returns undefined

@janpio janpio added the topic: enum "type"/block `enum` label Mar 4, 2023
@AntoineBW
Copy link
Author

We already fixed some enum related bugs, can you maybe try with prisma@dev and @prisma/client@dev? Maybe this is already fixed. Thanks.

@janpio Tested under 4.12.0-dev.6 and it works

@mmachatschek
Copy link

The bugfix on prisma 4.12.0-dev.6 works for me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: enum "type"/block `enum` topic: jsonProtocol
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants