Review main Ready for review Quiet

96120[BUGFIX] Use TCA default for columns created from TCA

Wolfgang Klinger CR 0 V -1 Hard +670 −22 updated 11/05/26, 20:01

Commit message

DefaultTcaSchema creates database columns for TCA fields that are
not defined in ext_tables.sql. Most field types ignored the TCA
"default" and used a fixed 0 or empty string instead. Rows that are
not written through the DataHandler therefore got a wrong value.

The types color, email, input, language, link, number and radio now
use the configured default. A default that does not fit the column
falls back to the previous value and a warning is logged: a text
longer than the column, or a negative number for an unsigned column.
Decimal defaults are rounded to the column scale, so the database
compare stays stable.

Datetime keeps its fixed default, because its TCA default is often
dynamic, e.g. time(). Password keeps it as well, a default would be
stored without being hashed.

After updating, the database analyzer shows changed defaults for
affected columns, e.g. sys_workspace.previewlink_lifetime now
defaults to 48. Existing rows are not modified.

Test this change

Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch

Check out patch set 6
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/20/96120/6 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/20/96120/6 && git cherry-pick FETCH_HEAD

Review

  • Code review CR 0 Needs a vote
  • Verified V -1 Blocked
    • core-ci -1 CI

Merge conflicts 5

Issues 2

Files 3

Review log 1824

  1. Wolfgang Klinger uploaded patch set 1 09/28/26, 09:25

  2. Mathias Brodala commented on patch set 1 09/28/26, 09:31

    DefaultTcaSchema.php:568

    Actually the TCA default can be used here, too. TCA is cached, so pure TCA/overrides will always define a static "default". If one makes the mistake to use time(), TCA will contain the timestamp from the time it was cached. So it would be consistent to apply this to the DB default as well.

    DefaultTcaSchema.php:1094

    Should we log a message if the default exceeds the field length? I can already imagine that this will be obscure and hard to debug. (Same goes for integer/dedimal default.)
  3. core-ci voted on patch set 1 V +1 09/28/26, 09:34 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/109401

  4. Wolfgang Klinger uploaded patch set 2 V +1 09/28/26, 09:48

  5. Wolfgang Klinger commented on patch set 1 09/28/26, 09:50

    DefaultTcaSchema.php:568 Reply

    Each time, time() gives a new value. So the database analyzer would show a changed default for sys_file_metadata.content_creation_date and content_modification_date again and again. Core itself uses 'default' => time() there. Also, the default would be the time of the last cache flush, which is IMHO not a useful value for new rows (makes no sense?). I would keep datetime out of this change.

    DefaultTcaSchema.php:1094 Reply

    Done
  6. Mathias Brodala commented on patch set 2 09/28/26, 09:55

    DefaultTcaSchema.php:568 Reply

    Hm, not sure if I'm missing something but the 'default' => time() pattern can never meet the expectation. That TYPO3 itself uses it looks like a bug. As explained, a default like this will be fixed to the timestamp when the TCA was cached. So even if this pattern is basically wrong, the DB default should still follow the TCA default here: both will change once the TCA cache is flushed and rebuilt. IMO they should be the same.
  7. core-ci voted on patch set 2 V +1 09/28/26, 09:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/109403

  8. Wolfgang Klinger commented on patch set 2 09/28/26, 09:57

    DefaultTcaSchema.php:568 Reply

    I don't really have an opinion on this—who should decide?
  9. Mathias Brodala commented on patch set 2 09/28/26, 10:05

    DefaultTcaSchema.php:568 Reply

    I've just asked in Slack about this, maybe someone else has an idea.
  10. Daniel Windloff commented on patch set 2 09/28/26, 15:49

    Hey Wolfgang, thanks a lot for the patch. I understand the intention to establish consistency here. I don't have a 100% answer, but I have a few thoughts on the approach to schema creation and a possible alternative: - The basic idea at the time wasn't to create a database schema that always fits, but rather to offer a default schema. - Default values ​​in TYPO3 are a topic in themselves. I've been following some changes for a while now to sort things out in the DataHandler for specific cases. Default values ​​can be overridden in the TCA for the columns, per type, or via child records. They also depend on UsrTsConfig and PageTsConfig. In my view, there isn't really a "true" default value. Therefore, I find it difficult to define anything definitively, what is needed here. - The TcaSchemaApi doesn't offer default values ​​for all columns. For this, I introduced the `hasDefaultValue` method. Generally, they can't be derived this way. Some default values ​​are actually instructions to the DataHandler to generate the actual values ​​(type: slug and uuid). - Deriving the schema from potentially changing values ​​like `time()` don't feel right. With our deployments, this would result in a database schema change every time. A possible alternative, in my view, would be to take the other approach: using the database default value in the DataHandler if no value can be derived from the TCA/TSConfig etc. This way, one single value could also be defined consistently. Such an approach is already used for redirects (see https://git.typo3.org/typo3/typo3/-/blob/main/typo3/sysext/redirects/Classes/Service/SlugService.php?ref_type=heads#L386 ). If this would be an alternative for you, it could be added after the patch (https://review.typo3.org/c/Packages/TYPO3.CMS/+/90484 ), which first clarifies the default values handling in the DataHandler. For that patch, a prepatch is nessesary atm, that's why I can't finish it atm. What do you think about that approch?
  11. Wolfgang Klinger commented on patch set 2 09/28/26, 17:18

    Reply

    Thanks, I think your alternative would not help here, because it only changes the DataHandler. To me the two changes look complementary: this one for the database schema, yours for the DataHandler fallback after #90484. Or do you mean that the schema should stay as it is, and extensions that need a database default should declare the column in ext_tables.sql?
  12. Daniel Windloff commented on patch set 2 09/28/26, 18:21

    Reply

    Yes, my suggestion was to add the column to `ext_tables.sql` with the default value and use this value in DataHandler if no other value has been defined as default. This would lead to consistent default values, and the developer has a chance to set an overall default value without doubt. The generated default schema should stay as it is.
  13. Markus Klein uploaded patch set 3 V +1 10/28/26, 20:37

  14. core-ci voted on patch set 3 V -1 10/28/26, 20:42 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112752

  15. Markus Klein uploaded patch set 4 V -1 11/04/26, 13:48

  16. core-ci voted on patch set 4 V -1 11/04/26, 13:56 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/113278

  17. Markus Klein uploaded patch set 5 V -1 11/04/26, 23:25

  18. core-ci voted on patch set 5 V +1 11/04/26, 23:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/113326

  19. Markus Klein commented on patch set 5 11/05/26, 01:44

    Add missing default for datetime

    DefaultTcaSchema.php:568 Reply

    let's include the default for SQL. Most datetime fields have a correct default value configured. using `time()` is at your own risk and yes, will change with every TCA cache flush.
  20. Markus Klein uploaded patch set 6 V +1 11/05/26, 08:20

  21. Markus Klein commented on patch set 5 11/05/26, 08:20

    Reply

    Done
  22. Markus Klein commented on patch set 6 11/05/26, 08:23

    Reply

    I took the liberty to update this patch. I believe TCA should be the truth. If stuff is changed via TSconfig, one has to change the type / default in their ext_tables.sql
  23. core-ci voted on patch set 6 V -1 11/05/26, 08:42 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/113361

  24. Daniel Windloff commented on patch set 6 11/05/26, 20:01

    Reply Unresolved

    Since a clear default isn't always evident from a TCA perspective, I still don't think it's the best approch atm. However, I do agree with the fundamental approach of having TCA as a single source of truth.
    Generally, I've been wondering whether the default values ​​set in this way shouldn't be validated (such as email address, color, country, etc.). Previously, all default values ​​from the TCA were processed by the DataHandler and thus validated. Furthermore, these newly set default values ​​might circumvent unique validations with meaningful values. I'm unsure about potential side effects.

    DefaultTcaSchema.php:669 Unresolved

    As 0 is the default language I suggest keeping 0 here.

    DefaultTcaSchema.php:1096 Unresolved

    Check for `$fieldType->hasDefaultValue()` is missing. A default value must not be set for every field type. If no default value has been set, the former default should be used.

    DefaultTcaSchema.php:1118 Unresolved

    Check for $fieldType->hasDefaultValue() is missing

    DefaultTcaSchema.php:1131 Unresolved

    Check for $fieldType->hasDefaultValue() is missing

    DefaultTcaSchema.php:1131 Unresolved

    this should depend on `$fieldType->getScale()`