#98224Predefined extbase model property value cause exception of not existing database field
Description
After adding a predefined value to a field which TCA type is set to “none” and the property annotation is @Transient, TYPO3 tries to persist this predefined value to a none existing database field, which ends in an exception.
The (simplified) model:
<?php
namespace Vendor\Extension\Domain\Model;
use TYPO3\CMS\Extbase\Annotation\ORM\Transient;
class Location extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* @var float
* @Transient
*/
protected float $distance = 0.0;
public function setDistance(float $distance): void
{
$this->distance = $distance;
}
public function getDistance(): float
{
return $this->distance;
}
}
The relevant TCA field config:
'columns' => [
'distance' => [
'config' => [
'type' => 'none',
],
],
]
I use this field to add a calculated distance to a location depending of the users location.
Then only way to get rid of this problem is to remove the predefinition value “0.0” from the property and change the getter this way:
public function getDistance(): float
{
return $this->distance ?? 0.0;
}Reviews 1
History 1113
-
Alexander Grein commented <span data-processor="relativetime" data-value="2022-08-29T09:36:34+00:00" > 08/29/22, 09:36 </span>
-
Alexander Grein changed PHP Version
8.28.1 <span data-processor="relativetime" data-value="2022-08-29T10:16:38+00:00" > 08/29/22, 10:16 </span> -
Alexander Grein commented <span data-processor="relativetime" data-value="2022-11-09T18:56:24+00:00" > 11/09/22, 18:56 </span>
Am I the only one with this problem?
To make it more clear, this example code of the official documentation is not working!:
https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ExtensionArchitecture/Extbase/Reference/Annotations.html#transient -
Georg Ringer changed Duplicated by #91726 <span data-processor="relativetime" data-value="2025-04-09T20:55:28+00:00" > 04/09/25, 20:55 </span>
-
Gerrit Code Review pushed patch set 1 for main to change 89664 status
NewUnder Review <span data-processor="relativetime" data-value="2025-06-06T15:10:11+00:00" > 06/06/25, 15:10 </span> -
Stefan Froemken commented <span data-processor="relativetime" data-value="2025-06-06T15:15:26+00:00" > 06/06/25, 15:15 </span>
I have never worked with that, so, maybe yes, you’re the only one ;-)
I have provided a patch. Would be cool if you can also test that. Sure, I have added Tests, but as you have an example by hand, you can test on a real-life example.
Stefan
-
Gerrit Code Review pushed patch set 2 for main to change 89664 <span data-processor="relativetime" data-value="2025-06-06T15:22:33+00:00" > 06/06/25, 15:22 </span>
-
Tobi Kretschmann commented <span data-processor="relativetime" data-value="2025-07-23T09:47:08+00:00" > 07/23/25, 09:47 </span>
Stefan Froemken wrote in #note-6:
> I have never worked with that, so, maybe yes, you’re the only one ;-)I can confirm behavior this with TYPO3 12 and PHP 8.3. Also the “workaround” works.
-
Alexander Grein commented and changed PHP Version
8.18.3 <span data-processor="relativetime" data-value="2026-01-15T15:17:26+00:00" > 01/15/26, 15:17 </span>With TYPO3 13.4.x things get even worse.
The official way (https://docs.typo3.org/permalink/t3coreapi:extbase-attribute-transient) doesn’t work at all:<?php namespace Vendor\Extension\Domain\Model; use TYPO3\CMS\Extbase\Annotation\ORM\Transient; class Location extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity { #[Transient()] protected float $distance = 0.0; }The persistent manager needs a db field “distance” and writes data into, independent of the annotation :-(
-
Garvin Hicking commented <span data-processor="relativetime" data-value="2026-01-15T16:00:45+00:00" > 01/15/26, 16:00 </span>
Yes, the patch discussion also contains that ‘transient’ is not really properly evaluated in the TYPO3 core. The docs are not right in this case and would need adjustment to state the non-working facts of this.
Just to understand the goal of this; why don’t you actually persist the “distance” and actually do create the column? I assume you try to carry state in that property from one extbase form/action to another. Could the distance instead be calcuated dynamically via actually persisted properties? It could be cached in the setter and persisted (and updated). That might make the domain logic even more sound in your application.
-
Alexander Grein commented <span data-processor="relativetime" data-value="2026-01-15T17:13:38+00:00" > 01/15/26, 17:13 </span>
The origin cause of this issue is not my current problem. This might can be “fixed” by using a DTO.
In my current case I need to add the (primary) bank account to a user model, which in the end can become more than one.
That’s why I use an ObjectStorage<bankaccount> in the “bankAccount” property of the user model.<br>Since I do not found a way to validate this single bank account datas (owner, iban, bic, institute) before persisting, I added this “initial” bank account datas as additional properties to my user model and store them to the bankAccount ObjectStorage in a second step (in an event listener). Since I do not want to store the bank data twice, I tried to use the mentioned Transient annotation.</bankaccount>See: https://typo3.slack.com/archives/C0NAHDRJB/p1768469902951959
-
Garvin Hicking commented <span data-processor="relativetime" data-value="2026-01-15T18:07:04+00:00" > 01/15/26, 18:07 </span>
Okay I see. Have you tried to use a controller-based argument validation? There you could iterate on the whole model more easily and add validation errors.
Also a custom validator on the domain model property should allow you to iterate all instances of bank accounts and then do validation on the “sub-properties”. If I understand correctly.Would you care to create an example of what you tried? That’s a seperate thing to we might better do on slack than here.
Just because currently I’d say the likely outcome will be that “transient” might go away, or only be addressed in a version (v14) that won’t help you too… much…
-
Garvin Hicking commented and changed status
Under ReviewClosed <span data-processor="relativetime" data-value="2026-10-02T10:25:39+00:00" > 10/02/26, 10:25 </span>See gerrit patch discussion
Additional to removing the default value from the property, I also have to remove the php >=7.4 property type.
Not working:
working: