phpcr-odm
phpcr-odm copied to clipboard
Regression when persisting object ID and changing the locale
A test has been added in the RoutingAutoBundle which seems to reveal a regression introduced in 83863d7e460c112aff1497abc4fdfb9c7b93cde2.
Failure is as follows
1) Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Functional\EventListener\AutoRouteListenerTest::testMultilangArticleRemainsSameLocale
Undefined index: path
/home/daniel/www/symfony-cmf/RoutingAutoBundle/vendor/symfony/phpunit-bridge/DeprecationErrorHandler.php:40
/home/daniel/www/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/UnitOfWork.php:1604
/home/daniel/www/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/UnitOfWork.php:1123
/home/daniel/www/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/UnitOfWork.php:2157
/home/daniel/www/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/DocumentManager.php:949
/home/daniel/www/symfony-cmf/RoutingAutoBundle/Tests/Functional/EventListener/AutoRouteListenerTest.php:288
Where path
is the name of the property mapped as the @Id
.
/cc @lsmith77 @WouterJ
I suspect it is caused by this PR: https://github.com/doctrine/phpcr-odm/pull/555 (which was merged in 1.2.0-RC4, the first version failing). So this has to be fixed in both 1.2.x and master.
Btw, the problem probably is not in the fact that path is the Id, but that the Id is one of the types that is not translatable. Only the translatable fields seem to exists at the line of the error.
ok, I know what the problem is.
When the changeset if calculated the "isNew" flag is determined by the presence of the object ID in the $originalData
array. If isNew is false then we expect all the fields to be present in the $originalData
.
The problem is caused when we call findTranslation
. This causes the UOW to set the originalData
with only the translated fields. It seems it expects that the originalData already has been initialized (with all the fields).
I am not sure how to fix this but I think it is invalid to call findTranslation
before a document is persisted. /cc @lsmith77 @dbu
oh my. well, you can bindTranslation before persisting, so findTranslation must work as well. i guess we should fix this edge case, maybe in bindTranslation to create all the expected data. or in findTranslation to not create any originalData when the document is new, because it actually makes no sense. could the later be the right solution?
Had another go at this, but failed. Maybe another day.