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

Doctrine's criteria causing "a new entity was found" error during batch update all #1415

Closed
jimsafley opened this issue May 21, 2019 · 1 comment
Milestone

Comments

@jimsafley
Copy link
Member

Running a batch update all may throw the following exception:

2019-05-08T18:44:31+00:00 ERR (3): Doctrine\ORM\ORMInvalidArgumentException: A new entity was found through the relationship 'Omeka\Entity\Value#resource' that was not configured to cascade persist operations for entity: Omeka\Entity\Item@00000000161f4291000000005cd06bdd. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist  this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'Omeka\Entity\Resource#__toString()' to get a clue. in /mnt/1TB/html/omeka-s/vendor/doctrine/orm/lib/Doctrine/ORM/ORMInvalidArgumentException.php:92
Stack trace:
#0 /mnt/1TB/html/omeka-s/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(852): Doctrine\ORM\ORMInvalidArgumentException::newEntityFoundThroughRelationship(Array, Object(Omeka\Entity\Item))
#1 /mnt/1TB/html/omeka-s/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(740): Doctrine\ORM\UnitOfWork->computeAssociationChanges(Array, Object(Omeka\Entity\Item))
#2 /mnt/1TB/html/omeka-s/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(802): Doctrine\ORM\UnitOfWork->computeChangeSet(Object(Doctrine\ORM\Mapping\ClassMetadata), Object(Omeka\Entity\Value))
#3 /mnt/1TB/html/omeka-s/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(340): Doctrine\ORM\UnitOfWork->computeChangeSets()
#4 /mnt/1TB/html/omeka-s/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(356): Doctrine\ORM\UnitOfWork->commit(NULL)
#5 /mnt/1TB/html/omeka-s/application/src/Api/Adapter/AbstractEntityAdapter.php(406): Doctrine\ORM\EntityManager->flush()
#6 /mnt/1TB/html/omeka-s/application/src/Api/Manager.php(236): Omeka\Api\Adapter\AbstractEntityAdapter->batchUpdate(Object(Omeka\Api\Request))
#7 /mnt/1TB/html/omeka-s/application/src/Api/Manager.php(146): Omeka\Api\Manager->execute(Object(Omeka\Api\Request))
#8 /mnt/1TB/html/omeka-s/application/src/Job/BatchUpdate.php(30): Omeka\Api\Manager->batchUpdate('items', Array, Array, Array)
#9 /mnt/1TB/html/omeka-s/application/src/Job/DispatchStrategy/Synchronous.php(34): Omeka\Job\BatchUpdate->perform()
#10 /mnt/1TB/html/omeka-s/application/src/Job/Dispatcher.php(105): Omeka\Job\DispatchStrategy\Synchronous->send(Object(Omeka\Entity\Job))
#11 /mnt/1TB/html/omeka-s/application/data/scripts/perform-job.php(43): Omeka\Job\Dispatcher->send(Object(Omeka\Entity\Job), Object(Omeka\Job\DispatchStrategy\Synchronous))
#12 {main}

It seems that three conditions must be met to see this bug:

  • The user clears a property value via the form's "Clear property values" control;
  • The BatchUpdate job runs batchUpdate() more than once (more than one iteration);
  • The values to be cleared do not exist (it works if the values exist)

Our use of Doctrine's criteria is likely the cause here. This patch fixes the problem by removing the offending criteria and filtering manually. Prior to this we attempted to detach the Value after it was used and, while that fixed the issue, it replicated resource titles somehow.

This observation may be helpful diagnosing this problem.

I have two items and I set the BatchUpdate job to iterate one item at a time. I add a dcterms:abstract value to item #1 and run "Clear property values" for dcterms:abstract. The job runs successfully, deleting the value. Then I add a dcterms:abstract value to item #2 and run "Clear property values" for dcterms:abstract. The job results in the "A new entity was found" error.

@jimsafley
Copy link
Member Author

The recent upgrade to Doctrine 2.6 does not fix this bug.

@zerocrates zerocrates added this to the June 17 2019 milestone Jun 3, 2019
zerocrates added a commit that referenced this issue Jun 27, 2019
Instead of detaching the touched entities, keep track of what the
EM was managing before the batch, and detach everything not in that set.

Intended to resolve an issue where Criteria usage causes entities to be
managed by the EM but not connected to the related entity the Criteria
was run against, meaning our usual strategy of relying on "cascade
detach" did not work.

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

No branches or pull requests

2 participants