Review main Merged

93040[BUGFIX] Allow persistence to non-uid tables in SaveToDatabaseFinisher

Garvin Hicking CR +2 V +2 Normal +86 −1 updated 03/04/26, 13:56

Commit message

The SaveToDdbFinisher allows persistence to tables that have no
UID column (like "sys_category_record_mm". In this case, a call
to "lastInsertId()" throws an exception (on mysql connections for
example).

With this patch, that exception is caught gracefully. A test
is added to verify this behavior no longer throws an exception.

Review

  • Code review CR +2 Done
    • Garvin Hicking +2
    • Oliver Klee +1
    • Anja Leichsenring +1
    • Josua Vogel +1
  • Verified V +2 Done
    • Garvin Hicking +2
    • Oliver Klee +1
    • Anja Leichsenring +1
    • Josua Vogel +1
    • core-ci +1 CI

Issues 1

Files 2

Review log 2328

Show 23 earlier messages
  1. Garvin Hicking uploaded patch set 1 03/03/26, 08:10

  2. core-ci voted on patch set 1 V -1 03/03/26, 08:21 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97156

  3. Garvin Hicking commented on patch set 2 V -1 03/03/26, 08:39

    Published edit on patch set 1.
  1. Oliver Klee voted on patch set 2 CR +1 V +1 03/03/26, 08:43

  2. core-ci voted on patch set 2 V +1 03/03/26, 08:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97159

  3. Josua Vogel commented on patch set 2 03/03/26, 11:28

    SaveToDatabaseFinisher.php:345

    the changelog says: "Instead of returning an empty value, Connection::lastInsertId() throws an exception when there's no identity value." Could it be a good idea to set an empty value here instead of 0?
  4. Christian Kuhn commented on patch set 2 03/03/26, 11:35

    SaveToDatabaseFinisherTest.php:30

    this is default.
  5. Josua Vogel commented on patch set 2 CR -1 03/03/26, 11:48

    I think we can improve the test. I´ll have a look
  6. Josua Vogel uploaded patch set 3 CR +1 V +1 03/03/26, 11:58

  7. Josua Vogel commented on patch set 3 03/03/26, 11:58

    SaveToDatabaseFinisherTest.php:30 Reply

    Done
  8. Josua Vogel commented on patch set 3 03/03/26, 12:08

    SaveToDatabaseFinisher.php:345 Reply

    maybe we should use getFinisherVariableProvider()->add() only, if a lastInsertId is available and add a debug or info log inside the catch ("row inserted, but no uid...")
  9. core-ci voted on patch set 3 V +1 03/03/26, 12:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97175

  10. Garvin Hicking commented on patch set 3 03/03/26, 16:02

    thanks for the test update, that broader test will surely help in the future

    SaveToDatabaseFinisher.php:345 Reply

    I'm happy for suggestions. I don't think the value will ever be evaluated inside a finisher.
  11. Garvin Hicking commented on patch set 3 03/03/26, 21:47

    SaveToDatabaseFinisher.php:345 Reply

    After thinking a bit on this I would say: - we should not "skip" setting an iterationCount variable, to not mess with missing lookup variables? - uid=0 should ideally not trigger any "if $insertedUids.XX" statements to be true, and provide least side effects - I don't think we should add a debug or info log, as this would unnecessarily spam the database. If developers store to a database table, they should be aware of this. As of now the bug is blocking insertions though Would you be fine with that?
  12. Josua Vogel commented on patch set 3 CR +1 V +1 03/04/26, 05:48

    SaveToDatabaseFinisher.php:345 Reply

    Yes, good points. I‘m fine with this
  13. Elias Häußler commented on patch set 3 03/04/26, 07:02

    I wonder if this works as expected. When adding these assertions to the test case, the second assertion fails because the actual value is `0` where I'd have expected it to be `0`: ``` self::assertTrue($finisherContext->getFinisherVariableProvider()->exists('SaveToDatabase', 'insertedUids.0')); self::assertSame(0, $finisherContext->getFinisherVariableProvider()->get('SaveToDatabase', 'insertedUids.0')); ```
  14. Elias Häußler commented on patch set 3 03/04/26, 07:03

    Reply

    Sorry, the actual value is `1` and not `0`, but the expectation is `0`.
  15. Elias Häußler commented on patch set 3 03/04/26, 07:43

    Reply

    My fault, I wasn't aware that SQLite behaves differently than other DBMSs like MySQL (thanks @garvin@hick.ing!). The following works with my assertion: ``` Build/Scripts/runTests.sh -s functional -d mysql -- --filter insertIntoTableWithoutUidColumnCreatesRow ``` I'd still like to have these assertions in place, since I consider them relevant for the actual test. Something like this should work across all available DBMSs: ``` $databasePlatform = $this->getConnectionPool()->getConnectionForTable('sys_category_record_mm')->getDatabasePlatform(); // These assertions only work for non-SQLite DBMSs since SQLite returns an unexpected value for lastInsertId if (!$databasePlatform instanceof SQLitePlatform) { self::assertTrue($finisherContext->getFinisherVariableProvider()->exists('SaveToDatabase', 'insertedUids.0')); self::assertSame(0, $finisherContext->getFinisherVariableProvider()->get('SaveToDatabase', 'insertedUids.0')); } ```
  16. Elias Häußler uploaded patch set 4 CR +1 V +1 03/04/26, 08:37

  17. Elias Häußler commented on patch set 4 03/04/26, 08:37

    Reply

    Done
  18. Oliver Klee voted on patch set 4 CR +1 V +1 03/04/26, 08:38

  19. Garvin Hicking commented on patch set 4 03/04/26, 08:41

    Reply

    Thank you! That's very helpful to assert, agreed. Cool you took care of it.
  20. core-ci voted on patch set 4 V -1 03/04/26, 08:59 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97273

  21. core-ci voted on patch set 4 V +1 03/04/26, 10:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97273

  22. Josua Vogel voted on patch set 4 CR +1 V +1 03/04/26, 10:16

  23. Anja Leichsenring voted on patch set 4 CR +1 V +1 03/04/26, 12:54

  24. Garvin Hicking voted on patch set 4 CR +2 V +2 03/04/26, 13:04

  25. Garvin Hicking merged patch set 5 03/04/26, 13:56