#90212updateObject() can loose data when handling related objects
Description
When inserting a new object which has new relating objects attached, updateObject() is called more than once to amend data to the new objects.
If the related object is translateable, and has the fields configured, _localizedUid can already be 0 in the object, which is then tested as true not being null in typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php Line 932 (Typo3 9.5), overwriting the uid with 0 in the following line effectively generating an update-query to uid=0 which of course fails silently.
In the scenario where this popped up I had the loss of data ranged from the pid not set on the related data-row up to complete relation information missing in the related data-row, like ‘tablenames’,‘fieldname’ and ‘uid_foreign’ – effectively destroying the relation.
casting the value of $object->_getProperty(‘_localizedUid’) to int and testing for !== 0 will fix this issue:
--- Backend.php 2020-01-26 18:47:11.000000000 +0100
+++ private/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php 2020-01-26 18:47:34.000000000 +0100
@@ -929,7 +929,7 @@
$row['uid'] = $object->getUid();
if ($dataMap->getLanguageIdColumnName() !== null) {
$row[$dataMap->getLanguageIdColumnName()] = (int)$object->_getProperty('_languageUid');
- if ($object->_getProperty('_localizedUid') !== null) {
+ if ((int)$object->_getProperty('_localizedUid') !== 0) {
$row['uid'] = $object->_getProperty('_localizedUid');
}
}
the concrete example was the generation of sys_file_references from uploaded files. The PID was never set correctly because of that, and when handling multiple files with ObjectStorages the relation-data was missing because of the problem above
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
History 2
-
Alexander Schnitzler changed Tags persistence <span data-processor="relativetime" data-value="2020-04-16T17:10:37+00:00" > 04/16/20, 17:10 </span>
-
Benni Mack commented and changed status
NewClosed <span data-processor="relativetime" data-value="2026-11-09T11:58:35+00:00" > 11/09/26, 11:58 </span>
I checked this against the current main branch and cannot reproduce it without custom code.
The `_localizedUid` property of AbstractDomainObject is now declared as `?int` and defaults to `null`. The only place that sets it is DataMapper::thawProperties(), which uses the uid (or `_LOCALIZED_UID`) of a record fetched from the database, so it is never 0. New objects keep `null` through insertObject(), and updateObject() then falls back to getUid() as intended. The property mapper cannot set it either, because it is protected and has no setter.
For `_localizedUid` to be 0, extension code has to set it, for example a custom FileReference model for uploads that initialises or overrides the property. In that case the fix belongs in the extension: leave the property alone so it stays `null` for new objects.
I’m closing this issue. If you can still reproduce it on TYPO3 13.4 or 14.x without code that touches `_localizedUid`, please reopen it with the steps (model, TCA and controller action).