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

Merge entity associated to versioned entity #1573

Merged
merged 4 commits into from Dec 11, 2015

Conversation

moroine
Copy link

@moroine moroine commented Nov 27, 2015

I wrote a unit test that reveal the bug and a fix.

If I merge an entity which is associated to a versioned entity this fire a OptimisticLockException as the managedCopy is a Proxy so the version attribute is always null.

I think when we compare version attribute, we should skip it when one of the entity or the managed copy is a Proxy not initialized.

try {
$articleMerged = $this->_em->merge($article);
$mergeSucceed = true;
} catch (OptimisticLockException $e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this try-catch


/**
* Category constructor.
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove this empty line

@@ -1905,6 +1905,18 @@ private function doMerge($entity, array &$visited, $prevManagedCopy = null, $ass
}

/**
* Tests if an entity is a non initialized proxy class
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be clearer to flip this function and rewrite it as a positive-question, where you're asking if the entity has any data to work with.

private function isLoaded($entity){
    return !($entity instanceof Proxy) || $entity->__isInitialized();
}

Other possible names that come to mind are hasData() or isInitialized(). (Assuming that non-proxies are considered initialized too.)

*/
public function __construct()
{
$this->tags = new ArrayCollection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a public $tags earlier on?

Ocramius added a commit that referenced this pull request Dec 11, 2015
Ocramius added a commit that referenced this pull request Dec 11, 2015
Ocramius added a commit that referenced this pull request Dec 11, 2015
Ocramius added a commit that referenced this pull request Dec 11, 2015
@Ocramius Ocramius merged commit fb4d02c into doctrine:master Dec 11, 2015
Ocramius added a commit that referenced this pull request Dec 11, 2015
Ocramius added a commit that referenced this pull request Dec 11, 2015
Ocramius added a commit that referenced this pull request Dec 11, 2015
@Ocramius
Copy link
Member

Merged, thanks!

Backported also in 2.5.x via 62719f2

@Ocramius Ocramius self-assigned this Dec 11, 2015
@Ocramius Ocramius added this to the 2.5.3 milestone Dec 11, 2015
@moroine
Copy link
Author

moroine commented Dec 14, 2015

Great !
My first contribution on an Open Source Project !!

@Ocramius
Copy link
Member

slow_clap_citizen_kane

@Ocramius
Copy link
Member

Also: welcome to this vicious circle of self-slavery called "open source software" ;-)

@moroine moroine deleted the MergeVersioned branch December 14, 2015 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants