Bug #77617
closedDataMapper stores implementation class name in persistence session, but looks up the original class name
100%
Description
Hi community
as written in the subject, the DataMapper does not respond to changing the implementing class when looking up objects in it's persistence session.
Inside the DataMapper::mapSingleRow
if ($this->identityMap->hasIdentifier($row['uid'], $className)) { $object = $this->identityMap->getObjectByIdentifier($row['uid'], $className); } else { $object = $this->createEmptyObject($className); $this->identityMap->registerObject($object, $row['uid']); $this->thawProperties($object, $row); $object->_memorizeCleanState(); $this->persistenceSession->registerReconstitutedEntity($object); } return $object;
The hasIdentifier check verifies (ultimately against the persistence session) if the object already has been reconstituted in this session. It uses the $className that was actually supplied. However, during createEmptyObject, the Object Container actually checks if the $className has a different implementing class (set by e.g. by using config.tx_extbase.objects).
Container::getEmptyObject
$className = $this->getImplementationClassName($className);
This means that the resulting object can be different than the class used to look up if said object is already part of the persistence session. In effect, this means the "_hasIdentifier_" check will always return FALSE when checking a $className that has a different implementing class.
This leads to unnecessary reconstitution of objects that are already part of the session. Furthermore, it leads to object reference problems as e.g. a repository will return the same instance of an object when it's implementation hasn't been overwritten, but it will return two different instances of the object when it has. This is very hard to catch when using "===" operations to check for object equality, which is done e.g. by some versions of Powermail.
This issue was found in TYPO3 Version 6.2; looking at the current 7.2 branch it looks like it's present there as well, though.
Cheers
Erik
Updated by Riccardo De Contardi over 6 years ago
- Status changed from New to Needs Feedback
Hi, my apologies for this so late reply.
May I ask if this issue is still present on more recent versions like 8.7.x or 9 (latest master) ?
By the way: I've seen that "identityMap" has been removed since 7.3
Updated by Riccardo De Contardi about 6 years ago
- Status changed from Needs Feedback to New
Updated by Markus Klösges almost 6 years ago
- TYPO3 Version changed from 6.2 to 8
I can confirm this behaviour on 8.7.20.
The analysis is exact as of today.
Patching DataMapper::getTargetType()
with an additional$targetType = GeneralUtility::makeInstance(Container::class)->getImplementationClassName($targetType);
fixes the problem.
Updated by Gerrit Code Review almost 6 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58959
Updated by Gerrit Code Review almost 6 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58959
Updated by Gerrit Code Review almost 6 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58959
Updated by Gerrit Code Review almost 6 years ago
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58959
Updated by Gerrit Code Review almost 6 years ago
Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58959
Updated by Gerrit Code Review almost 6 years ago
Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58959
Updated by Gerrit Code Review almost 6 years ago
Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58959
Updated by Gerrit Code Review almost 6 years ago
Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58959
Updated by Gerrit Code Review almost 6 years ago
Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58959
Updated by Gerrit Code Review almost 6 years ago
Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59619
Updated by Markus Klösges almost 6 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 4c0fd85fa51a769f3fb5a9744d58155c05dbdfce.