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

DDC-1925: Bug in UnitOfWork and ManyToMany relations #2594

Closed
doctrinebot opened this issue Jul 14, 2012 · 20 comments
Closed

DDC-1925: Bug in UnitOfWork and ManyToMany relations #2594

doctrinebot opened this issue Jul 14, 2012 · 20 comments
Assignees
Labels
Milestone

Comments

@doctrinebot
Copy link

Jira issue originally created by user zhil:

Lets say, I have entity Forum with ManyToMany relations with User.
I need to validate user changes and I use code like

$uow = $this->getDoctrine()->getEntityManager()->getUnitOfWork();
$uow->computeChangeSets();
$changeSet = $uow->getEntityChangeSet($forum);
if (.... bla-bla-bla....) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($forum);
$em->flush();
}

Unfortunately, whenever I try to change manyToMany relations - I got error
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '4-4' for key 'PRIMARY'

If I comment uow code - everything works just great.

It looks like bug in UnitOfWork implementation.

Let me know if you need more details from me.

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

What is the part you commented out? Also, in what context is your code executed?

@doctrinebot
Copy link
Author

Comment created by zhil:

I got error when $em->persist($forum); $em->flush(); executed.

I can create github repository with code, which reproduce this error, if you want.

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

Please do

@doctrinebot
Copy link
Author

Comment created by zhil:

that would be simple symfony2 application - will it work for you?

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

As long as the code is related to doctrine. Otherwise this issue is quite incomplete :)

@doctrinebot
Copy link
Author

Comment created by zhil:

Done, please check https://github.com/zhil/testDoctrine

In few words, when I add code like
$uow = $this->getDoctrine()->getEntityManager()->getUnitOfWork();
$uow->computeChangeSets();
$changeSet = $uow->getEntityChangeSet($product);

before $em->persist(); $em->flush();

I got fake MYSQL error :)

Thank in advance for your help :)

@doctrinebot
Copy link
Author

Comment created by zhil:

Just wonder - is it bug in doctrine2 or its problems somewhere else? (symfony2/my code/ etc.)

This is part of the live project - I need to fix it :)

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

I think it is related with the fact that you're using the UnitOfWork manually. You can probably try to fix the problem by moving your code to an event subscriber until this is fixed.

@doctrinebot
Copy link
Author

Comment created by zhil:

Well, I used UnitOfWork, because I need to know what was changed during object validation (for example, property status can be changed only in predefined cases etc.).

Ok, thanks for the suggestion - I will implement some temporary solution for this problem :)

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

I think I spotted where this happens, but I don't have a clear overview on the situation. Will try to work on this...

@doctrinebot
Copy link
Author

Comment created by zhil:

Thanks for the checking this issue.
I have already patched my application with ugly patch. Just in case solution will take some time and somebody else will need similar patch. I patched entity like

entity {
public $previousStatusBugfix = -1;
public function setStatus($status)
{
// check http://www.doctrine-project.org/jira/browse/[DDC-1925](http://www.doctrine-project.org/jira/browse/DDC-1925)?focusedCommentId=18344#comment-18344
// Ticket #651
$this->previousStatusBugfix = $this->status;
$this->status = $status;
}
}

and validator

if(($object->previousStatusBugfix != -1) && ($object->previousStatusBugfix != $object->getStatus())) {
$changeSet = array("status"=>array(0=>$object->previousStatusBugfix, 1=>$object->getStatus()));
}

:)

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

I just wrote a couple of tests (attaching them to the issue shortly) and found out that on >=2.2.x your code runs perfectly.
The problem is on the 2.1.x branch, and the commit that fixed the issue is 4474d30 for DDC-1210

Now looking if it can be merged into 2.1.x since it doesn't seem to cause any BC break.

@doctrinebot
Copy link
Author

Comment created by @beberlei:

A related Github Pull-Request [GH-402] was opened
#402

@doctrinebot
Copy link
Author

Comment created by @beberlei:

A related Github Pull-Request [GH-403] was opened
#403

@doctrinebot
Copy link
Author

Comment created by @Ocramius:

Duplicate of DDC-1210

@doctrinebot
Copy link
Author

Comment created by @beberlei:

A related Github Pull-Request [GH-403] was closed
#403

@doctrinebot
Copy link
Author

Comment created by @beberlei:

A related Github Pull-Request [GH-402] was closed
#402

@doctrinebot
Copy link
Author

Issue was closed with resolution "Fixed"

@doctrinebot
Copy link
Author

Comment created by @doctrinebot:

A related Github Pull-Request [GH-402] was closed:
doctrine/dbal#402

@doctrinebot
Copy link
Author

Comment created by @doctrinebot:

A related Github Pull-Request [GH-403] was closed:
doctrine/dbal#403

@doctrinebot doctrinebot added this to the 2.3 milestone Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants