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

Misleading Error for non-unique relation names #12986

Closed
Haschikeks opened this issue Apr 25, 2022 · 2 comments · Fixed by prisma/prisma-engines#2994
Closed

Misleading Error for non-unique relation names #12986

Haschikeks opened this issue Apr 25, 2022 · 2 comments · Fixed by prisma/prisma-engines#2994
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: dmmf
Milestone

Comments

@Haschikeks
Copy link

Bug description

If you have two relations, that use the same name @relation("a"), running prisma format returns an unspecific error message.

Prisma schema loaded from prisma/schema.prisma
thread '<unnamed>' panicked at 'Did not find a relation for model User and field comments', query-engine/prisma-models/src/builders/internal_dm_builder.rs:122:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: Unexpected token D in JSON at position 0
error Command failed with exit code 1.

Running the command with DEBUG="*" give me the following error

  prisma:engines binaries to download libquery-engine, migration-engine, introspection-engine, prisma-fmt +0ms
Prisma schema loaded from prisma/schema.prisma
  prisma:getDMMF Using CLI Query Engine (Node-API) at: /Users/***/projects/test/prisma-test/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node +0ms
thread '<unnamed>' panicked at 'Did not find a relation for model User and field comments', query-engine/prisma-models/src/builders/internal_dm_builder.rs:122:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: SyntaxError: Unexpected token D in JSON at position 0
    at JSON.parse (<anonymous>)
    at getDmmfNodeAPI (/Users/***/projects/test/prisma-test/node_modules/prisma/build/index.js:42643:28)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async getDMMF (/Users/***/projects/test/prisma-test/node_modules/prisma/build/index.js:42622:17)
    at async Object.parse (/Users/***/projects/test/prisma-test/node_modules/prisma/build/index.js:113414:5)
    at async main (/Users/***/projects/test/prisma-test/node_modules/prisma/build/index.js:115059:18)
error Command failed with exit code 1.

As a note, the VS Code prisma extension, does not throw an Error for this. (Which is somewhat okay for me)

How to reproduce

Example repository

https://github.com/Haschikeks/prisma-relation-name-bug

If you change the relation to be equal, for example both to a and then run prisma format the above mentioned error appears.

Expected behavior

It would be nice, if there was an error message that indicates, that there is a problem with the relation names. This would already help in tracking down the problem.

Prisma information

Prisma schema:

model Post {
  id     String @unique
  userId String
  user   User   @relation("a", fields: [userId], references: [id])
}

model User {
  id       String    @unique
  posts    Post[]    @relation("a")
  comments Comment[] @relation("a")
}

model Comment {
  id     String @unique
  userId String
  user   User   @relation("a", fields: [userId], references: [id])
}

Environment & setup

  • OS: Mac OS
  • Node.js version: v17.9.0

Prisma Version

prisma                  : 3.12.0
@prisma/client          : Not found
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : 22b822189f46ef0dc5c5b503368d1bee01213980
Studio                  : 0.459.0
@Haschikeks Haschikeks added the kind/bug A reported bug. label Apr 25, 2022
@tomhoule tomhoule added topic: dmmf team/client Issue for team Client. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Apr 25, 2022
@Weakky Weakky self-assigned this Jun 17, 2022
@Weakky Weakky added this to the 4.0.x milestone Jun 20, 2022
@Haschikeks
Copy link
Author

@Weakky thank you for attending to this problem. Just a quick follow up question.
With Version 4 we would then be able to have multiple relations that have the same name in the prisma schema?

@Weakky
Copy link
Member

Weakky commented Jun 22, 2022

With Version 4 we would then be able to have multiple relations that have the same name in the prisma schema?

Hey @Haschikeks, apologies I forgot to write an update here.

Yes, that's correct 👍.

Thanks for reporting this bug 🙏

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: dmmf
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants