Project

General

Profile

Actions

Bug #105490

closed

TCA-driven SQL auto-generation should not fallback to varchar for "item-less" selectSingle fields (purely itemsProcFunc/FormDataprovider-filled)

Added by S P 3 days ago. Updated 3 days ago.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2024-10-28
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
13
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

The global fallback for singleSelect fields is currently a varchar(255). On some projects we have single selects which are filled solely by a FormDataProvider or via an itemsProcFunc. For these I have to do this hack to get an int field if I'd like to use SQL auto generation:

'config' => [
    'type' => 'select',
    'renderType' => 'selectSingle',
    'items' => [
        [
            'label' => 'dummy-for-sql-generation|array-filled-by-form-data-provider',
            'value' => 0,
        ],
    ],
],

IMHO, singleSelect fields with neither predefined items nor foreignTable should be INT UNSIGNED as fallback. Or at least there should be a TCA option to define a SQL column type directly in TCA (like dbColumnType, like there is for the dbFieldLength already).

I assume the varchar fallback is there "to be safe" (no accidental data truncating on v13 upgrade), but checking the column defintions is up to the upgrading developer anyway when he deletes the ext_tables.sql lines. Someone who is cabable of custom-filling an entire select field should also be able to check the SQL column type on an upgrade.


Related issues 1 (1 open0 closed)

Related to TYPO3 Core - Bug #105441: Autogeneration of selectSingle with foreign_table and a custom item with value null tries to create a varchar fieldNew2024-10-24

Actions
Actions #1

Updated by Garvin Hicking 3 days ago

  • Status changed from New to Needs Feedback

One can specify that in an extension's ext_tables.sql however. If we were to change this now, it would be a breaking change along with a needed deprecation in v14, so it wouldn't materialize before v15.

A data provider / itemsProcFunc could provide strings too, so I don't think having an INT would be the "proper" choice here?

Thus I think changing this to INT would break much easier for developers, and break the assumption to "playing things safe" like you mentioned (because integer values could be saved as strings, but not the other way round).

Actions #2

Updated by S P 3 days ago

One can specify that in an extension's ext_tables.sql however.

Yes, of course. I only question the default column type. TYPO3 currently assumes that "varchar" is a safe default type if none other information is present for a single select field. However on other occurances it assumes TEXT as safe (types category, slug, group or non-singleSelect select, for example). So this is already inconsistent to other fields (including select itself!). The question is: why do singleSelect fields fall back to varchar in the first place? Personally, I'd prefer INT UNSIGNED, but at least to be consistent with all other fields it should be TEXT.

Actions #3

Updated by Garvin Hicking 3 days ago

The reasoning is that select <option> fields rarely have big chunks of text in it? Varchars have index/storage advantages (with disadvantages too of course). This is a place where we can utilize it by "plausibility".

Actions #4

Updated by S P 3 days ago

Garvin Hicking wrote in #note-3:

The reasoning is that select <option> fields rarely have big chunks of text in it? Varchars have index/storage advantages (with disadvantages too of course). This is a place where we can utilize it by "plausibility".

I know all of this. But then I ask the other way round, why is the global fallback for non-singleSelect select fields TEXT and not varchar? :) Of course, it is TEXT because of long CSV values exceeding 255 chars. So we have the case that select fields can be "anything", decided by non-obvious column config combinations, see also: #105441 (where null alongside only-ints is casted to varchar instead of int).

Actions #5

Updated by S P 3 days ago

  • Related to Bug #105441: Autogeneration of selectSingle with foreign_table and a custom item with value null tries to create a varchar field added
Actions #6

Updated by Garvin Hicking 3 days ago

I don't enjoy the tone of the conversation. I'm leaving it for others to decide.

Actions #7

Updated by Georg Ringer 3 days ago

  • Status changed from Needs Feedback to Rejected

as there is a easy way to overrule the default field and changing the default is highly breaking I am closing this issue.

hope you understand

Actions #8

Updated by S P 3 days ago

Georg Ringer wrote in #note-7:

hope you understand

I don't really care, after all some colum type has to be the default. ;) I just found it inconsistent that a select field can have three different SQL column type defaults, depending on not-really-documented combinations of the config options of select fields (the 1200 lines switch in DefaultTcaSchema.php of ext:core is the "documentation"). I'd expected selectSingle to be either UNSIGEND INT (because it usually holds a uid) or TEXT (the same fallback as other select fields have) -- but instead there pops up a VARCHAR (even if no dbFieldLength is specified!), that's all I questioned/wondered.

Actions

Also available in: Atom PDF