Review main Merged

89607[BUGFIX] Cast record type to a string

Georg Ringer CR +2 V +2 Easy +1 −1 updated 06/05/25, 10:30

Commit message

If the record type is an integer, it must be casted to a string to avoid
an exception creating a DataMap object.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Christian Kuhn +1
    • Nikita Hovratov +1
  • Verified V +2 Done
    • Benni Mack +2
    • Christian Kuhn +1
    • Nikita Hovratov +1
    • core-ci +1 CI

Issues 2

Files 1

Review log 1719

  1. Georg Ringer uploaded patch set 1 06/02/25, 20:34

  2. Georg Ringer commented on patch set 1 06/02/25, 20:35

    This change is ready for review.
  3. core-ci voted on patch set 1 V +1 06/02/25, 20:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79774

  4. Benjamin Franzke commented on patch set 1 06/03/25, 05:37

    If it is *valid* for a record type to be an integer, shouldn't the model (`DataMap::recordType`) allow `string|int|null` then? I mean, if the record type is really an integer, why would we normalize that to a string? But I'm a bit puzzled what's right here, because EXT:news has some inconsistencies regarding the type: The Extbase persistence and also the TCA configuration uses `int`: https://github.com/georgringer/news/blob/6eb63d5fa8c903c164ff76d644737e04019967aa/Configuration/Extbase/Persistence/Classes.php#L23 https://github.com/georgringer/news/blob/6eb63d5fa8c903c164ff76d644737e04019967aa/Configuration/TCA/tx_news_domain_model_news.php#L332-L334 …while the SQL definition defines the type field to be a `string`: https://github.com/georgringer/news/blob/6eb63d5fa8c903c164ff76d644737e04019967aa/ext_tables.sql#L19 My question is: Did you use type string in ext_tables.sql, because a real integer field "never" worked? (I don't know why it shouldn't, pages.doktype is a real int as well) If that's the case an integer based configuration in Extbase persistence and TCA is just wrong… So, sorry for the long text, but I think we should try to use allow `string|int|null`, which actually reflects the state before the refactoring that broke your usecase: > 87347: [TASK] Turn extbase DataMap into a readonly DO | https://review.typo3.org/c/Packages/TYPO3.CMS/+/87347
  5. Benjamin Franzke commented on patch set 1 06/03/25, 05:38

    We should add `Related: #105757` to document why only `main` is targeted.
  6. Christian Kuhn commented on patch set 1 CR +1 06/03/25, 10:29

    Reply

    Yeah. First, as you mentioned, this obviously came from https://review.typo3.org/c/Packages/TYPO3.CMS/+/87347 where i picked the type annotations that have been there for a very long time already and turned them into typed properties. Looking at core, it seems both 'int' and 'varchar' in SQL is used: pages.doktype is int, others use string and often mix them with 'default zero' treated as string (tt_content.CType, fe_users.tx_extbase_type). FormEngine says (it actively casts to string in DatabaseRecordTypeValue): // The tca record type value of the record. Forced to string, there can be "named" type values. 'recordTypeValue' => '', -> it seems the current situation is "you can store as int if there are ints only, but it will be treated as string in the framework". I'd say that's a sane solution: "Speaking" types are better than integer types for transparency (think of tt_content.CType "accordion" over "4287") and we should encourage to use strings for type fields. we won't change pages, though, mainly for b/w compat reasons, and we probably won't change the default 'zero'. From framework-user point of view, I think it is more easy if DataMap consumers can rely on string, have the cast from a potential int DB value done by the framework internally and have no own need to keep track of the subtle string|int difference in any higher level extbase consumer code. FormEngine does exactly this already by forcing string, so we are in line when extbase follows with a string cast as proposed by georg with the patch.
  7. Christian Kuhn commented on patch set 1 06/03/25, 10:29

    Reply

    yeah.
  8. Georg Ringer updated the commit message in patch set 2 CR +1 V +1 06/03/25, 11:06

  9. core-ci voted on patch set 2 V +1 06/03/25, 11:12 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79796

  10. Christian Kuhn voted on patch set 2 CR +1 V +1 06/03/25, 11:35

  11. Nikita Hovratov commented on patch set 2 CR +1 V +1 06/03/25, 13:27

    Agree with @lolli@schwarzbu.ch here. Only Page Types really use int because of legacy reasons. Even the default zero "0" is most of the time defined as string in TCA. Hopefully we can shift someday to speaking types everywhere.
  12. Christian Kuhn commented on patch set 2 06/04/25, 13:41

    Reply

    i hope this has been answered in a good way. i'll set the comment resolved. let's wait another day for potential further feedback and merge tomorrow if nothing pops up.

    Reply

    Done
  13. Benni Mack commented on patch set 2 CR +1 06/04/25, 14:35

    Reply

    I hope this will be gone soon everywhere... we use integer in a lot of places, when the typefield is a checkbox. This is fine though, as we _need_ to start treating types as strings (we do so in FormEngine and Schema API already).
  14. Benjamin Franzke commented on patch set 2 06/05/25, 06:32

    Reply

    ack, feel free to do so. I think it's wrong, but we do it wrong in schema api as well. We're "only" lucky that database engines are so forgiving, which "allows" us to pass integers as strings, which is the reason that we can simply discard the real type here. I can't vote positive myself, simply because I'm not agreeing with this type casts, but feel free to merge.
  15. Benni Mack commented on patch set 2 06/05/25, 08:05

    Reply

    I see the technical point here, but my huge main problem is that in the past, we had a lot of trouble when using TCA Types $GLOBALS['TCA']['be_users']['types'][0] vs. $GLOBALS['TCA']['be_users']['types']['0'] When people extend this in their Configuration/TCA/Overrides, this is very error prone. So, I always recommended to handle the types key as string (even if it is an integer field such as be_users.admin as type field) in the past. So, I designed Schema API to work like this. But if we would create a better "write API for TCA" we could loosen this up again. What I'm saying: In this case, I'm 100% in favor of improving DX over strictness in DB... for the time being.
  16. Benni Mack commented on patch set 2 06/05/25, 08:05

    Reply

    maybe a todo might be nice?
  17. Christian Kuhn commented on patch set 2 06/05/25, 09:14

    Reply

    iirc DH applies a cast before writing 'string 2' into DB when the DB column or the TCA type is int/number. if not, this could be fine-tuned, but i think we're rather safe on this side at the moment. alternatively, we could have migration code that forces TCA ctrl-type fields to varchar in db. this would be a good thing anyways in case we want to further encourage strings values. i don't see a good place for a todo at the moment.
  18. Benni Mack commented on patch set 2 CR +2 V +2 06/05/25, 10:30

    Reply

    Done
  19. Benni Mack merged patch set 3 06/05/25, 10:30