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

JSON protocol: sibling composites of the same type are rejected #18735

Closed
SevInf opened this issue Apr 13, 2023 · 3 comments · Fixed by prisma/prisma-engines#3878
Closed

JSON protocol: sibling composites of the same type are rejected #18735

SevInf opened this issue Apr 13, 2023 · 3 comments · Fixed by prisma/prisma-engines#3878
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: composite-types topic: jsonProtocol topic: mongodb
Milestone

Comments

@SevInf
Copy link
Contributor

SevInf commented Apr 13, 2023

With this schema:

generator client {
  provider = "prisma-client-js"
  output   = "../node_modules/.prisma/client"
}

datasource db {
  provider = "mongodb"
  url      = env("TEST_MONGO_URI")
}

model User {
  id         String    @id @map("_id")
  composite1 Composite
  composite2 Composite
}

type Composite {
  someField String
}

it is impossible to query User model without explicit selection:

PrismaClientUnknownRequestError:
Invalid `prisma.user.findFirst()` invocation in
/Users/serhii/projects/prisma/reproductions/workbench/index.ts:6:21

  3 const prisma = new PrismaClient()
  4
  5 async function main() {
 6   await prisma.user.findFirst(
$composites: true does not support recursive composite types.

composite1 and composite2 are siblings, but incorrectly detected as recursive composites.

Protocol request:

{
  "modelName": "User",
  "action": "findFirst",
  "query": {
    "arguments": {},
    "selection": {
      "$composites": true,
      "$scalars": true
    }
  }
}
@Weakky Weakky added the team/client Issue for team Client. label Apr 14, 2023
SevInf added a commit to prisma/prisma-engines that referenced this issue Apr 14, 2023
Problem: to detect recursive compsite, we track visited types and
return an error if we encountered same type twice. This misfires in
case we have sibling compsites fields of the same type - same type is
encountered twice in this case, but composite is not recursive.

Fixed by tracking (Type, Field) pairs instead. This way, we'll produce
an error only if we walked the same field twice, but allow same type to
be used for different fields.

Fix prisma/prisma#18735
SevInf added a commit to prisma/prisma-engines that referenced this issue Apr 14, 2023
Problem: to detect recursive compsite, we track visited types and
return an error if we encountered same type twice. This misfires in
case we have sibling compsites fields of the same type - same type is
encountered twice in this case, but composite is not recursive.

Fixed by tracking (Type, Field) pairs instead. This way, we'll produce
an error only if we walked the same field twice, but allow same type to
be used for different fields.

Fix prisma/prisma#18735
@janpio janpio added this to the 4.13.0 milestone Apr 15, 2023
@PinkaminaDianePie
Copy link

for me the fix doesn't work. schema:

type E {
  something Int
}

type D {
  e E
}

type B {
  d D
}

type C {
  d D
}

type A {
  b B
  c C
}

@PinkaminaDianePie
Copy link

as for 4.14.0 - issue still persists

@SevInf
Copy link
Contributor Author

SevInf commented May 22, 2023

I've opened a new issue, #19373, you can follow progress there.

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. team/client Issue for team Client. topic: composite-types topic: jsonProtocol topic: mongodb
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@janpio @SevInf @PinkaminaDianePie @Weakky and others