Skip to content

Rephrase ObjectManager::merge() BC break doc #251

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

Merged
merged 1 commit into from
Mar 14, 2022

Conversation

greg0ire
Copy link
Member

It refers to another deprecation that has been reverted.

It refers to another deprecation that has been reverted.
@greg0ire greg0ire requested a review from malarzm March 14, 2022 21:35
@malarzm malarzm added this to the 2.4.1 milestone Mar 14, 2022
@malarzm malarzm merged commit d3a1294 into doctrine:3.0.x Mar 14, 2022
@malarzm
Copy link
Member

malarzm commented Mar 14, 2022

Thanks @greg0ire!

@greg0ire greg0ire deleted the update-major-upgrade branch March 14, 2022 22:28
@gnutix
Copy link

gnutix commented Apr 4, 2022

Sorry to say that here, but every time I read this line of the doc, I feel like I've been given a 🖕. :/

Our project uses merge extensively in legacy code, and I have no idea how in hell I will be able to migrate our code when the time comes. I find it quite absurd for a library to just say "we've removed one of our feature because it was inconvenient for us, just deal with it" without providing an upgrade path, code examples, an external package or anything really...

@derrabus derrabus modified the milestones: 2.4.1, 3.0.0 Apr 4, 2022
@derrabus
Copy link
Member

derrabus commented Apr 4, 2022

I find it quite absurd for a library to just say "we've removed one of our feature because it was inconvenient for us, just deal with it"

For the record: Nobody says that.

@gnutix
Copy link

gnutix commented Apr 4, 2022

Thanks for answering without answering... For the record : the quote were not meant to imply someone said exactly that, but rather that that's how I interpreted every written sentence (in doc, issues, etc) related to the removal of this method I've ever read (and there's been some, I've been looking out for that problem for years now). Not once have I seen a comment that gave any support to the users of the library.

So again, my question is : is it possible to provide such a supportive answer ? One that provide an upgrade path, in the means of code examples, some separate repository with the code, or else... ?

Or is this method just impossible to migrate in any way, and every one using it have two choices : either throw their code away and close their business, or be stuck on a soon-to-be-outdated library version ? If so, I think this deprecation notice should have a bit more context and explain how everyone's using it is damned.

@malarzm
Copy link
Member

malarzm commented Apr 4, 2022

It's not possible to provide a clear migration path as there's too many ways one could use merge:

  • fetching data from some cache and merging -> SLC probably
  • fetching unserialized object from session and merging - it's asking for trouble anyway, just refetch the object and store id in session
  • random merge calls across the codebase - well, how can we say what to do? I've even seen random calls to merge that were discarding returned object. How can we advise?

That's just 3 usages from the top of my head I've seen over the years, but not the only ones. Upgrade path depends on why somebody used merge in the first place. It's just my personal opinion, but I've been using Doctrine for many years, wrote apps big and small, and never HAD to use merge. There were moments I could, it even could have been handy, but I decided not to and never looked back.

@gnutix
Copy link

gnutix commented Apr 4, 2022

I don't know what SLC refers to? Here's two of the most common usages in our codebase :

    public function save(Alert $alert)
    {
        if (!$alert->getId()) {
            $this->em->persist($alert);
        } else {
            $this->em->merge($alert);
        }
        $this->em->flush();

        return $alert;
    }

And sometimes, it's even :

    public function save(AbsenceRequest $absenceRequest)
    {
        $entity = $this->em->merge($absenceRequest);
        $this->em->flush($entity);

        return $entity;
    }

There are some more exotic usages too unfortunately that I can't really share as-is.

@malarzm
Copy link
Member

malarzm commented Apr 4, 2022

I don't know what SLC refers to?

Second Level Cache

Here's two of the most common usages in our codebase :

Your first example is exactly what I had in mind with "I've even seen random calls to merge that were discarding returned object. How can we advise?". Why are you merging the object, discarding what merge told you, and returning the original from method? This is not how merge is supposed to be used. Next, it's impossible to advise you without knowing the story why merge is even used. Why is it needed? In normal flow you'd be operating on an entity fetched from database and that's it. Why do you need to discard whatever is in UoW with what you're passing to the method? Do you rely on behavious that it's safe-ish to use merge on a managed entity but you want cascade to kick in? Do you even consider passing unmanaged entities to merge?

@derrabus
Copy link
Member

derrabus commented Apr 4, 2022

Sorry to interrupt again and not being helpful, but this is a merge request that fixed a tiny piece of documentation, not a support forum. Can we please use https://github.com/doctrine/orm/discussions for support questions (assuming that the ORM is the persitence implementation that is being used here)?

@malarzm
Copy link
Member

malarzm commented Apr 4, 2022

Feel free to mention me in a discussion thread if you create one as I'm not following all ORM activity. From my perspective your demonstrated usage of merge is a prominent example of why merge should be gone as it doesn't seem to be used properly (basing on provided examples).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants