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

[BREAKING CHANGE] Disconnect/connect (for relations) throws errors needlessly #5005

Closed
jhalborg opened this issue Sep 11, 2019 · 14 comments
Closed
Assignees
Labels
kind/improvement An improvement to existing feature and code. team/client Issue for team Client. topic: connect topic: relations

Comments

@jhalborg
Copy link

Problem

Currently when you try to connect or disconnect relationships, you need to be needlessly cautious that you haven't done it before, otherwise the command will throw.

It's weird that it throws, seeing as the state of the data afterwards is as the request wanted it in the first place anyway.

Here's an example:

await prisma.user.update({
    where: {
      id: 'u123',
    },
    data: {
      Post: {
        connect: {
          id: 'p123',
        },
      },
    },
  })

// will throw
await prisma.user.update({
    where: {
      id: 'u123',
    },
    data: {
      Post: {
        connect: {
          id: 'p123',
        },
      },
    },
  })

The same applies for disconnect.

Additional Context: https://prisma.slack.com/archives/CKQTGR6T0/p1568120850240700?thread_ts=1567958862.225000&cid=CKQTGR6T0

Suggested Solution

Don't throw. Allow connects and disconnects to either apply the change or ignore the action.

@janpio janpio transferred this issue from prisma/prisma Dec 13, 2019
@pantharshit00
Copy link
Contributor

Current behaviour is photon will also throw if you try to connect to a already existing connected node.
image

We might need a product decision here on what we want the actual behaviour to be.

@RafaelKr
Copy link
Contributor

When finally deciding what the behavior should be, you should also take into consideration how Photon will ensure a working connection when running on serverless infrastructure, especially after a frozen function is resumed. In the best case this just happens automatically.

Besides that I also wouldn't expect it to throw. As stated by @jhalborg the requested state is the current state.

Otherwise I currently can't think of a real case where a developer has to call connect when he is already connected to a database. Only with bad state management or if a disconnect has failed somehow.

Nevertheless my opinion is that Photon shouldn't throw but instead log a warning which informs the developer that a call to connect/disconnect would not have been needed.

@janpio janpio assigned timsuchanek and mavilein and unassigned timsuchanek Jan 7, 2020
@mavilein
Copy link
Member

mavilein commented Jan 7, 2020

This not a bug as this is the intended behavior. Therefore marking it as a feature request. @sorenbs is the owner of the spec for this API. He should make a call whether we want to change this behavior.

@mavilein mavilein assigned sorenbs and unassigned mavilein Jan 7, 2020
@jhalborg
Copy link
Author

jhalborg commented Jan 8, 2020

@RafaelKr and @mavilein - I think you've misread the issue :-) I didn't mean connects/disconnects from the client to the database, but between related nodes in the data 😄 See the Slack link for more context

@mavilein
Copy link
Member

mavilein commented Jan 9, 2020

@jhalborg : I did not. My comment still stands. This was indeed intentional. @sorenbs will look into this and make a call. :-)

@jhalborg
Copy link
Author

jhalborg commented Jan 9, 2020

@mavilein Ah, OK - only @RafaelKr , then :-)

I'll just reiterate that I'd find it very unintuitive to have to handle an error for an operation that leads to the result I wanted from the operation :-)

@RafaelKr
Copy link
Contributor

RafaelKr commented Jan 9, 2020

@jhalborg You are right, I have indeed not paid enough attention and misunderstood it.

But still I have the same opinion for connecting/disconnecting relations: It shouldn't throw an error and in this case even no warning.

I don't know what exactly the Prisma Query Engine is doing, but I think when doing the same operation in raw SQL it also wouldn't throw an error. Am I right about this?

Maybe a comparable situation of real life that just came to my mind is that:
I ask my colleague "Could you please plug in/out my charger cable?", he replies "Okay", then he sees it's already plugged in/out and does nothing.

@janpio janpio changed the title Disconnect/connect throws errors needlessly Disconnect/connect throws errors needlessly (link/unlink) Jan 16, 2020
@janpio
Copy link
Member

janpio commented Mar 3, 2020

Internal Note: This might make sense, but we don't have time to think about it right now.

@jhalborg
Copy link
Author

jhalborg commented Mar 9, 2020

@janpio - Wouldn't it make sense to spend time on this before GA of the client, as it would otherwise lead to a lot of error-handling code for users of the library that shouldn't be necessary, and that would have to be removed if this is implemented later on? I think it'll save your users a lot of code, time and confusion.

@janpio
Copy link
Member

janpio commented Mar 9, 2020

Certainly, but we can not do all the things that would make sense right now, so we have to make decisions where to focus on. Fixing real bugs and finishing functionality that is needed currently is higher on that list. But we will get to this.

@matthewmueller matthewmueller changed the title Disconnect/connect throws errors needlessly (link/unlink) Disconnect/connect throws errors needlessly May 26, 2020
@matthewmueller
Copy link
Contributor

Hey @jhalborg, I re-wrote your initial problem statement. I hope you don't mind!

@janpio janpio changed the title Disconnect/connect throws errors needlessly Disconnect/connect (for relations) throws errors needlessly Jun 11, 2020
@jkb-kt
Copy link

jkb-kt commented Sep 17, 2020

When can we expect this done, please?

@mavilein mavilein changed the title Disconnect/connect (for relations) throws errors needlessly [BREAKING CHANGE] Disconnect/connect (for relations) throws errors needlessly Sep 23, 2020
@pantharshit00 pantharshit00 transferred this issue from prisma/prisma-client-js Jan 13, 2021
@pantharshit00 pantharshit00 added kind/improvement An improvement to existing feature and code. team/client Issue for team Client. labels Jan 13, 2021
@matthewmueller matthewmueller added this to the 2.17.0 milestone Feb 3, 2021
@matthewmueller
Copy link
Contributor

Next Step:

  • Check that this works

@matthewmueller matthewmueller added this to the 2.30.0 milestone Aug 11, 2021
@matthewmueller matthewmueller modified the milestones: 2.30.0, 2.31.0 / 3.0.x Aug 24, 2021
@matthewmueller
Copy link
Contributor

matthewmueller commented Sep 6, 2021

This works now, if you try to connect an already connected relation, it's a no-op.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/improvement An improvement to existing feature and code. team/client Issue for team Client. topic: connect topic: relations
Projects
None yet
Development

No branches or pull requests

9 participants