Review 14.3 Merged

94891[BUGFIX] Honor parameter types in writable Connection methods

Stefan Bürk CR +2 V +2 Hard +385 −22 updated 07/23/26, 07:50

Commit message

With #99062 native json field support has been introduced
along with automatic and forceful to-database value transformation
when using the following methods:

* `Connection::insert()`
* `Connection::update()`
* `Connection::bulkInsert()`

The intent of this change was to automatically map native PHP data
structures like `array` to JSON fields, but also introduced other
convenience mappings, like supporting automatic `\DateTime`
transformation to database values.

In other words, our raw connection API became a mini ORM, that
was automatically triggered based on database introspection.
Note: upstream doctrine `Connection` API supports this transformation
as well, but only if the parameter type (that does the actually
transformation) has been passed explicitly, while we autodetected
the type and applied it regardless of possible user input.

This forceful automatism broke consumers that already used JSON
database types, because `json_encode` is not idempotent and a
string that was already json encoded became double json encoded,
as it was passed a second time through `json_encode`.

Without taking this automatism away, we now restrict it to be
optional and no longer forceful, to only apply if no explicit doctrine
type parameter is given.

If a consumer of the `Connection` methods supplies a parameter type, it
is now honored and therefore allows to perform raw insertion, by using
doctrine binding types (`\Doctrine\DBAL\ParameterType::*`) instead of
doctrine mapping types (`\Doctrine\DBAL\Type\*`).

This improved handling is now used by Extbase (which does a to-database
transformation on its own) to prevent double encoding of already
prepared database field values:

The Extbase `Typo3DbBackend` uses the cached SchemaInformation
to pass the binding types `ParameterTypes` for all fields,
to ensure that data is inserted as-is, while preserving support
for all databases that require LOB handling for binary fields.

In the future, we may remove the Extbase internal handling
and use the `Doctrine DBAL` type conversion directly and
reduce a maintenance level, which
needs a little bit more of preparation work and brain to
achieve that.

Tests with Extbase usage and persisting models with loaded
data containing json encoded strings were missing and lead
to the issues and the reason to put additional tests with
this change into place, to have at least these cases covered.

Review

  • Code review CR +2 Done
    • Stefan Bürk +2
  • Verified V +2 Done
    • Stefan Bürk +2
    • core-ci +1 CI

Issues 3

Files 23

Show 3 more files

Review log 34

  1. Stefan Bürk uploaded patch set 1 07/23/26, 07:42

  2. core-ci voted on patch set 1 V +1 07/23/26, 07:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/105217

  3. Stefan Bürk voted on patch set 1 CR +2 V +2 07/23/26, 07:50

  4. Stefan Bürk merged patch set 2 07/23/26, 07:50