Issue Bug Closed

#105062Extbase DataMapper type error, for empty passthrough relation (since 13.3.0)

Armin Vieweg 09/20/24, 09:21 updated 12/02/25, 14:33

Description

I get this error (in DCE extension) when updating from 13.2.1 to 13.3.0:

> TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::thawObjectProperty(): Return value must be of type ?object, array returned in /var/www/html/vendor/typo3/cms-extbase/Classes/Persistence/Generic/Mapper/DataMapper.php line 308

The problem is a column which is from type “passthrough” and got the value 0.

In \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::getEmptyRelationValue the $relatesToOne variable is false (in v13.3.0) which returns an empty array, instead of null. In v13.2.1 this variable is true.

The getEmptyRelationValue-Method is being called by mapObjectToClassProperty which is being called by thawObjectProperty. But thawObjectProperty has typehinting ?object which causes the type error, because of the returned empty array.

Reviews 2

History 1621

  1. Armin Vieweg commented <span data-processor="relativetime" data-value="2024-09-20T09:40:18+00:00" > 09/20/24, 09:40 </span>

    After further debugging I found the root of this issue:

    In \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMapFactory::setRelations this condition has been added:

    if ($field instanceof RelationalFieldTypeInterface === false) {
         return $columnMap;
    }

    And $field which is an instance of \TYPO3\CMS\Core\Schema\Field\PassthroughFieldType does not implement the RelationalFieldTypeInterface.

    —-

    That means, you can not use Extbase relations with a passthrough TCA configuration, anymore.

    This circumstance is not mentioned in the changelog of 13.3, and is breaking 🫤

  2. Armin Vieweg changed subject Extbase DataMapper type error, for empty relation (since 13.3.0) Extbase DataMapper type error, for empty passthrough relation (since 13.3.0) <span data-processor="relativetime" data-value="2024-09-20T09:50:41+00:00" > 09/20/24, 09:50 </span>

  3. Nikita Hovratov commented <span data-processor="relativetime" data-value="2024-09-20T13:24:02+00:00" > 09/20/24, 13:24 </span>

    Armin, could you point us to the place in your extension, which does not work anymore?

  4. Garvin Hicking commented and changed status New Needs Feedback <span data-processor="relativetime" data-value="2024-09-20T15:05:00+00:00" > 09/20/24, 15:05 </span>

    From typo3-cms-coredev slack, just for completion:

    Person1: IMO this sounds like something which only worked by accident. So 
    far Extbase relations always need proper relational fields in TCA as foundation.
    
    Person2: I guess there was manual typeconverting/datamapping etc. involved,
    but the current bug probably seems to prevent any kind of operation
    on the raw data (edited) 
    
    Person3: Looks like it would work for Collection type hint like 
    ObjectStorage<FooBar> eventhough it is of type passthrough.
    Last time I tried, I couldn't resolve relations for type passthrough though. 
    Would need to check for what DCE is doing there exactly.
    I know it does some auto magic record to Domain Model mapping on the fly.
  5. Armin Vieweg commented <span data-processor="relativetime" data-value="2024-09-20T18:09:10+00:00" > 09/20/24, 18:09 </span>

    In DCE this issue occures in DceField Extbase model, in the field parentField.

    In TCA this is defined as passthrough.

    When I change it to eg. select and define a foreign_table, it works.

  6. Nikita Hovratov commented <span data-processor="relativetime" data-value="2024-09-20T20:17:05+00:00" > 09/20/24, 20:17 </span>

    Okay, so I checked this in one of my projects to understand why this didn’t work for me even in v12.
    Indeed, extbase did add a “hasOne” relation type to passthrough fields, if they define a proper type in their Model.
    And it even resolves the relations for simple “findAll” queries.
    However, the created ColumnMap does not have the information of the related table. Extbase somehow manages to find the table by the Model type alone.
    This stops working as soon as you create constraints in your query referencing the passthrough field.
    This is because Typo3DbQueryParser only relies on the ColumnMap information.

    So in conclusion: Yes it worked (a bit) before. But only for simple use cases. However, this was always semantically wrong and I don’t think it is documented anywhere.
    The question of whether this is breaking is a question of “bug or feature”.
    We should examine, how common this is and act accordingly. It is easy to fix, though. Doing it the right way in v13 will also benefit from proper TcaSchema and Core RelationResolving.

    At the very least, we should add an “Important.rst” to explain this beavior.

  7. Armin Vieweg commented <span data-processor="relativetime" data-value="2024-09-21T13:13:21+00:00" > 09/21/24, 13:13 </span>

    I know several projects, where passthrough has been used for Extbase relations. All of them will break now.

    I agree that the new way is the way to go, but it should be mentioned somewhere.

    Maybe the TCA checks would be a nice place for that. Although the scope need to get extended to cover Extbase models (and it’s properties) as well.

  8. Benni Mack commented <span data-processor="relativetime" data-value="2024-10-07T11:52:29+00:00" > 10/07/24, 11:52 </span>

    Hey Armin & Nikita,

    although I think this was a bug before, we either need to

    a) bring back the state as before and mark it as breaking in v14
    b) evaluate additional parts of passthrough to make this happen in v13 too (which might be nice actually)

    WDYT?

  9. Armin Vieweg commented <span data-processor="relativetime" data-value="2024-10-08T07:01:43+00:00" > 10/08/24, 07:01 </span>

    Hi Benni,

    I think your second suggestion would not work, because usually passthrough fields have got no additional parts you could evaluate.

    To do so you would need to check the related property in Extbase entity, which involves reflection and Extbase mapping configuration.

    So, I think your first suggestion is the better one. I would also be fine with, keeping it as it is now, and just add a breaking note to the current changelog, although the final LTS release should not contain breaking changes.

    In this case I would argue, that it is a bug fix in changelog, which missed the breaking change when it has been introduced.

  10. S P commented <span data-processor="relativetime" data-value="2024-10-29T09:49:23+00:00" > 10/29/24, 09:49 </span>

    I can confirm this bug. Upgraded from 12 to 13. For us this happens on a field configured like this, the items will all be from one single target table, but filled purely by an ItemProvider:

    'config' => [
        'type' => 'select',
        'renderType' => 'selectSingle',
        'items' => [
            [
                'label' => 'dummy-for-sql-generation-to-get-an-int-field-and-no-varchar|array-filled-by-item-provider',
                'value' => 0,
            ],
        ],
    ],

    But, no matter what the intended behaviour is: the Extbase DataMapper still has a PHP type juggling bug. The method thawObjectProperty(): ?object should not simply no-check return from mapObjectToClassProperty(): mixed (where mixed can, and will, happen to be an array, as we see in this bug). This type juggling must somehow be caught and avoided by proper type hints or checks or exceptions.

  11. S P commented <span data-processor="relativetime" data-value="2024-10-29T11:00:55+00:00" > 10/29/24, 11:00 </span>

    My workaround is this:

    'config' => [
        'type' => 'select',
        'renderType' => 'selectSingle',
        // items array filled by item provider!
        // foreign_table and foreign_table_where are in here only because of this bug:
        // https://forge.typo3.org/issues/105062
        // extbase needs a foreign table configured in TCA to correctly detect it as relation field
        // the where condition is there to break the SQL query (performance),
        // which would otherwise be executed fully in backend context
        'foreign_table' => 'my_table',
        'foreign_table_where' => 'AND FALSE LIMIT 0',
    ],
  12. Gerrit Code Review pushed patch set 1 for main to change 86957 status Needs Feedback Under Review <span data-processor="relativetime" data-value="2024-11-11T19:26:15+00:00" > 11/11/24, 19:26 </span>

  13. Oliver Bartsch commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2024-11-12T07:15:10+00:00" > 11/12/24, 07:15 </span>

    Applied in changeset commit:8c292a7819015988a1ed3d5d13d27c36e74d2e6d.