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

Prisma lift error: ambiguous self-relation detected #488

Closed
iherger opened this issue Sep 3, 2019 · 16 comments
Closed

Prisma lift error: ambiguous self-relation detected #488

iherger opened this issue Sep 3, 2019 · 16 comments
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug.
Milestone

Comments

@iherger
Copy link

iherger commented Sep 3, 2019

I accidentally had an error in a data model definition, which lead to a self-referencing model (related should have been pointing to a different model B, and not to A ):

model A {
  id      String @default(cuid()) @id @unique
  name    String    
  related A[] 
}

With this data model:

  • the first invocation of prisma2 lift save/up was successful.
  • further invocations of prisma2 lift save/up failed silently. Debugging showed the error message "Ambiguous self relation detected."

Expected behaviour:

  1. at the first invocation of prisma2 lift save/up, report the "Ambiguous self relation detected." message, and prevent the creation of the ambiguous self relation.
  2. don't fail silently, but actually display the error message
@pantharshit00
Copy link
Contributor

Hi,

I am unable to reproduce this. The exact steps I took are:

  1. prisma2 init
  2. Added the model and migrated the datamodel using lift:
model A {
  id      String @default(cuid()) @id @unique
  name    String    
  related A[] 
}
  1. Added the further model to the datamodel and remigrated using lift:
model B {
  id   String @default(cuid()) @id
  name String
  test Int
}
  1. Deployment was successful and the underlying data structure is correct.
    image

@pantharshit00 pantharshit00 added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. labels Sep 4, 2019
@divyenduz
Copy link
Contributor

I am able to repro this: https://github.com/divyendu-test/p2-488

Thanks to a nice and shiny debugging session with @momakes

@divyenduz divyenduz added process/candidate bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Sep 26, 2019
@janpio janpio added this to the Preview 14 milestone Sep 27, 2019
@imVinayPandya
Copy link

I am facing same issue, any solution/work around for this?

@divyenduz
Copy link
Contributor

@imVinayPandya We will work on this in this sprint 👍

@perlo27
Copy link

perlo27 commented Sep 30, 2019

After getting this error, is there any way to fall back?
I've tried to delete migration and change back .prisma file, but still having this error, probably it's cached somewhere?

@tomhoule
Copy link
Contributor

tomhoule commented Oct 1, 2019

This should be fixed by prisma/prisma-engines#82

The problem was that we weren't separating between models when validating that relation fields weren't causing any ambiguity, so there were false positives. The fix will be in the next preview :)

The PR also contains another change that makes the check for ambiguity in self relationships (model fields that refer to the same model) stricter.

Before, with this model:

model Human {
    id Int @id
    parent Human
    child Human
}

we would have inferred a single self-relation with parent and child as the two ends.

Now this model is invalid, you need to specify whether you want two self relations or one, by using @relation("NameOfTheRelation").

More info on this change in this schema spec PR: prisma/specs#201

@tomhoule tomhoule closed this as completed Oct 1, 2019
@divyenduz
Copy link
Contributor

Reopening while this is not in alpha 🙏

@divyenduz divyenduz reopened this Oct 2, 2019
@abdusamadtv
Copy link

I accidentally had an error in a data model definition, which lead to a self-referencing model (related should have been pointing to a different model B, and not to A ):

model A {
  id      String @default(cuid()) @id @unique
  name    String    
  related A[] 
}

With this data model:

  • the first invocation of prisma2 lift save/up was successful.
  • further invocations of prisma2 lift save/up failed silently. Debugging showed the error message "Ambiguous self relation detected."

Expected behaviour:

  1. at the first invocation of prisma2 lift save/up, report the "Ambiguous self relation detected." message, and prevent the creation of the ambiguous self relation.
  2. don't fail silently, but actually display the error message

I had the same schema and everything was good, but today after adding some new fields I've started to get this error

image

Here's my schema

image

I tried this friends User[] @relation(name: "UserFriends") but I'm still getting error

@iaarab
Copy link

iaarab commented Oct 4, 2019

I get this error while running the prisma2 init hello-prisma and selecting photon only:

image

@janpio
Copy link
Member

janpio commented Oct 4, 2019

Both @iaarab and @AbdusamadTurdiev, please both open a new issue and include all the relevant information so that what we can reproduce and later investigate what is going on. (The individual steps how you get your schema, and the schema as text (if possible) would help a lot.)

@abdusamadtv
Copy link

is this going to be fixed guys?

@pantharshit00
Copy link
Contributor

@AbdusamadTurdiev This has been fixed in the engine by prisma/prisma-engines#82 as mentioned by @tomhoule.

This hasn't been released yet so we have kept the PR open

@mavilein
Copy link
Member

A fix for this was merged to alpha 9 days ago. It will be released as a normal preview tomorrow.
Forgot to close this.

@nhuesmann
Copy link

@mavilein I am still having this issue in prisma2@2.0.0-preview014, binary version: 188a379c9b8c6650e5812f9bdb7407d7b197692f. Preview 14 states it fixes this bug. Should I open a new issue, or post my schema here?

@mavilein
Copy link
Member

@nhuesmann : Open a new one please 🙏

@nhuesmann
Copy link

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

No branches or pull requests