-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Loaded entities in column formatter seem to be treated as new entities in 1.9.0 #1862
Comments
@jaapromijn i dont think this commit breaks the unique constraint here. It executes an extra flush on Doctrine ORm when it hits the batchsize. However i see you grab a random user from your existing ORM here in a callback without using a generator? |
@pimjansen The The doctrine documentation says the following about clear:
Could you point me to an example of using the generator to return a random entity from the database? |
@jaapromijn correct however since all is flushed already, clearing and detaching it should not be a problem? Can you explain the use case, since looking at the code you are quering all users and are populating those again? Isnt it a bit normal that it gives duplicates in that case? |
@pimjansen Thanks for your time. We are generating So for the |
@jaapromijn ok but where is then the unique constraint coming from? Since i dont see you use a check to prevent that? |
The users are being created before the statuses: $populator->addEntity(User::class, 4, [
'roles' => function () use ($generator) {
$roles = ['ROLE_CONTRACTOR', 'ROLE_USER', 'ROLE_CONTRACTOR_USER'];
$key = array_rand($roles);
return [$roles[$key]];
},
'username' => function () use ($generator) {
return $generator->unique()->userName().'@example.com';
},
'magicLinkToken' => function () use ($generator) {
return md5('test');
},
]);
$populator->execute($manager); A seperate execute has been called. |
@pimjansen, I have the same issue as @jaapromijn. Having roughly something like:
in
When I comment out the mentioned line
on (roughly - kept the relevant properties only):
A similar issue seems to be described here https://stackoverflow.com/questions/18215975/doctrine-a-new-entity-was-found-through-the-relationship. |
Could someone create a patch PR for this? Lets revert the clear due to sidefx then. |
Sorry that I didn't get back to this. I adjusted the code of my fixture generator class in such a way this is no longer an issue for our project. Our code contained multiple An example of how that would work: $entities = $populator->execute($manager); $this->reassignBooks($entities, $manager); /**
* Re-assign books that are not linked to an author.
*/
private function reassignBooks(array $entities, ObjectManager $manager): void
{
$authors = $entities[Author::class];
$books = $entities[Book::class];
foreach ($books as $book) {
if ($book->getUser()->getAuthor() === null) {
$key = array_rand($authors);
$author = $authors[$key];
$book->setUser($author->getUser());
$manager->persist($book);
}
}
} This is a suitable solution because we don't generate really large datasets. |
@pimjansen, I created #1995. I tried my best, but please ping me if you need it to be alterned. |
…or (#1995) Bug: #1862 Clear specific entities is deprecated and will not be supported in Doctrine 3.0. (doctrine/orm@9ccb883) Bug introduced: c49cd54 Related issue: https://stackoverflow.com/questions/18215975/doctrine-a-new-entity-was-found-through-the-relationship
* 'master' of github.com:Partoo/Faker: (294 commits) Fix (bug fzaninotto#1862): Do not clear entity manager for doctrine orm populator (fzaninotto#1995) Remove persian rude words. (fzaninotto#1879) Enhancement: Run builds on master using GitHub Actions Fix typo (fzaninotto#1927) Fix: Run build against PHP 7.4 Fix: Aggregate badges in one place (fzaninotto#1866) Added changelog for the 1.9.1 release Fix: Reduce visibility of setUp() and tearDown() (fzaninotto#1821) Enhancement: Collect code coverage (fzaninotto#1824) Enhancement: Use all columns when running tests Add link to PHPStan extension to readme (fzaninotto#1834) Enhancement: Configure verbose output via phpunit.xml.dist Update master version Bump version to 1.9 Curly braces for arrays is deprecated in PHP 7.4 (detected by PHPCompatibility) Updated indenting changelog Update changelog with 1.9.0 release Skipped lorumpixel test for the release where the service is pretty unstable Fix: Mark test classes as final Fix: Remove unnecessary class-level DocBlocks ...
Is there any ETA when this fix will be released? |
@pimjansen, following up @obstschale question: any ETA on that? |
…rm populator (fzaninotto#1995) Bug: fzaninotto#1862 Clear specific entities is deprecated and will not be supported in Doctrine 3.0. (doctrine/orm@9ccb883) Bug introduced: c49cd54 Related issue: https://stackoverflow.com/questions/18215975/doctrine-a-new-entity-was-found-through-the-relationship
…rm populator (fzaninotto#1995) Bug: fzaninotto#1862 Clear specific entities is deprecated and will not be supported in Doctrine 3.0. (doctrine/orm@9ccb883) Bug introduced: c49cd54 Related issue: https://stackoverflow.com/questions/18215975/doctrine-a-new-entity-was-found-through-the-relationship
Summary
When upgrading from 1.8.0 to 1.9.0, using a collection of existing entities in a column formatter results in an error.
It seems that the existing entities are now treated as new entities instead.
This seems to be caused by the addition in PR #1781: c49cd54#diff-d38baf8c465e27d0cc5334cf5d8475aaR105
Versions
fzaninotto/faker
Self-enclosed code snippet for reproduction
Expected output
Actual output
The text was updated successfully, but these errors were encountered: