Open DenyPt96 opened 2 months ago
It seems related to isInIdentityMap
, and there is two occurences https://github.com/search?q=repo%3Asonata-project%2FEntityAuditBundle+isInIdentityMap&type=code
I think we're passing the old data and the new data so without any more information, I would think you are passing string
instead of object
to one of your oTo/oTm/mTo/mTm relations.
I suspect that array_merge in the LogRevisionsListener::postUpdate() function (https://github.com/sonata-project/EntityAuditBundle/blob/1.12.0/src/EventListener/LogRevisionsListener.php#L246) provides an unexpected result for those entities which primary keys include a foreign key/relationship to another entity (which is our case with ProductCompany entity)
i have dumped data of each of the three arrays that are being merged there:
$this->getOriginalEntityData($em, $entity)
$uow->getEntityIdentifier($entity),
$this->getManyToManyRelations($em, $entity)
values from $uow->getEntityIdentifier($entity) override those from $this->getOriginalEntityData($em, $entity), so the resulting array is
in which the 'product' and 'company' entities have been replaced with only their ids
later this causes the 'spl_object_id() expects parameter 1 to be object, string given' TypeError in the LogRevisionsListener::saveRevisionEntityData() function (https://github.com/sonata-project/EntityAuditBundle/blob/1.12.0/src/EventListener/LogRevisionsListener.php#L522) where function \Doctrine\ORM\UnitOfWork::isInIdentityMap($entity) recieves 'PN0002624' in the $entity parameter, instead of the expected Product entity (the same would then happen for the 'PSP' string in place of the expected Company entity)
i think we are saving our entities correctly and this is an oversight in EntityAuditBundle related to primary keys composed of foreign keys (similar to https://github.com/sonata-project/EntityAuditBundle/issues/502)
Environment
Sonata packages
show
``` Direct dependencies required in composer.json: sonata-project/entity-audit-bundle 1.12.0 1.12.0 Audit for Doctrine Entities ```
Symfony packages
show
``` $ composer show --latest 'symfony/*' # Put the result here. ```
PHP version
Subject
Auditing entity which uses foreign key as primary key throws exception when entity manager flushes.
Minimal repository with the bug
Steps to reproduce
When entity manager flushes and exception is thrown: spl_object_id() expects parameter 1 to be object, string given![Screenshot from 2024-05-03 11-20-59](https://github.com/sonata-project/EntityAuditBundle/assets/119050501/1aa2b91e-1e89-4464-aa5e-c7abc0ec1018)
Table product:
![Screenshot from 2024-05-03 11-45-20](https://github.com/sonata-project/EntityAuditBundle/assets/119050501/48b2cb95-2af7-444c-9d83-57e5c4c893a0)
Table product_company![Screenshot from 2024-05-03 11-42-35](https://github.com/sonata-project/EntityAuditBundle/assets/119050501/a08fa7a5-b6a5-417e-aa16-82b2407b6569)
Expected results
Actual results