{"action":"created","issue":{"url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/1058","labels_url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/1058/labels{/name}","comments_url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/1058/comments","events_url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/1058/events","html_url":"https://github.com/doctrine/mongodb-odm/issues/1058","id":64657418,"number":1058,"title":"Document is upserted and then updated during one flush operation","user":{"login":"vkartaviy","id":648039,"avatar_url":"https://avatars.githubusercontent.com/u/648039?v=3","gravatar_id":"","url":"https://api.github.com/users/vkartaviy","html_url":"https://github.com/vkartaviy","followers_url":"https://api.github.com/users/vkartaviy/followers","following_url":"https://api.github.com/users/vkartaviy/following{/other_user}","gists_url":"https://api.github.com/users/vkartaviy/gists{/gist_id}","starred_url":"https://api.github.com/users/vkartaviy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkartaviy/subscriptions","organizations_url":"https://api.github.com/users/vkartaviy/orgs","repos_url":"https://api.github.com/users/vkartaviy/repos","events_url":"https://api.github.com/users/vkartaviy/events{/privacy}","received_events_url":"https://api.github.com/users/vkartaviy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-03-26T23:42:35Z","updated_at":"2015-03-27T17:26:16Z","closed_at":null,"body":"* I have document with ```pre-generated id``` so it added to ```documentUpserts``` array after calling ```$dm->persist($document)```\r\n\r\n* I have ```onFlush``` listener where I add some data to that document and then call ```$dm->getUnitOfWork()->recomputeSingleDocumentChangeSet($metadata, $document);```\r\n\r\n* I call ```$dm->flush()``` and see the next picture:\r\n```documentUpserts``` and ```documentUpdates``` has the same document to update.\r\n\r\nIt looks like the problem is [here](https://github.com/doctrine/mongodb-odm/blob/master/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L814),  in direct adding of the document to the ```documentUpdates``` array but should be through ```scheduleForUpdate``` method?\r\n"},"comment":{"url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/comments/87021018","html_url":"https://github.com/doctrine/mongodb-odm/issues/1058#issuecomment-87021018","issue_url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/1058","id":87021018,"user":{"login":"alcaeus","id":383198,"avatar_url":"https://avatars.githubusercontent.com/u/383198?v=3","gravatar_id":"","url":"https://api.github.com/users/alcaeus","html_url":"https://github.com/alcaeus","followers_url":"https://api.github.com/users/alcaeus/followers","following_url":"https://api.github.com/users/alcaeus/following{/other_user}","gists_url":"https://api.github.com/users/alcaeus/gists{/gist_id}","starred_url":"https://api.github.com/users/alcaeus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alcaeus/subscriptions","organizations_url":"https://api.github.com/users/alcaeus/orgs","repos_url":"https://api.github.com/users/alcaeus/repos","events_url":"https://api.github.com/users/alcaeus/events{/privacy}","received_events_url":"https://api.github.com/users/alcaeus/received_events","type":"User","site_admin":false},"created_at":"2015-03-27T17:26:16Z","updated_at":"2015-03-27T17:26:16Z","body":"That's the exception I was referring to, which is why I decided not to use ```scheduleForUpdate()``` and instead just check if it's there. I can change it, but probably won't get to it until Monday."}}