96351[BUGFIX] Persist Extbase class schemata when built
Commit message
Review
-
Code review CR 0
-
Verified V -1
- core-ci -1 CI
Issues 1
Files 5
- typo3/sysext/extbase/Classes/Reflection/ReflectionService.php+14 −33
- typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/test_validators/Classes/Domain/Model/ModelWithClosureDefaultValue.phpnew+34 −0
- typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/test_validators/Classes/Domain/Model/SymfonyModelWithClosureConstraint.phpnew+45 −0
- typo3/sysext/extbase/Tests/Functional/Reflection/ReflectionServiceTest.phpnew+60 −0
- typo3/sysext/extbase/Tests/Unit/Reflection/ReflectionServiceTest.php+27 −0
Review log 1416
-
Stefan Bürk uploaded patch set 1 10/04/26, 18:58
-
core-ci voted on patch set 1 V +1 10/04/26, 19:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110050
-
Stefan Bürk marked it ready for review 10/04/26, 20:28
-
Oliver Klee voted on patch set 1 V +1 10/05/26, 09:32
-
Alexander Schnitzler voted on patch set 1 CR +1 V +1 10/17/26, 06:23
-
Oliver Klee voted on patch set 1 CR +1 10/17/26, 17:07
-
Garvin Hicking commented on patch set 1 CR -1 10/19/26, 18:00
-
Alexander Schnitzler commented on patch set 1 V 0 10/19/26, 18:12
Resetting my verified vote since the test actually doesn't really test. I have never really seen anyone XClass the ReflectionService but if we are strict, this is possibly breaking, at least when backported. I don't see how this is a class people should use publicly no matter if it's marked internal but I let others decide here. A real test, one that also checks the Closure, would be great here. -
Garvin Hicking uploaded patch set 2
CR +1V +110/19/26, 18:55add currently failing closure test -
Garvin Hicking commented on patch set 2 10/19/26, 18:56
Reply Unresolved
Yeah I also agree that this is a very unlikely class anyone should touch. I'd be fine with a "breaking bugfix" on this, fwiw. I've added the test I came up with during review, which is red however until we decide how (if) a closure should be treated. -
core-ci voted on patch set 2 V -1 10/19/26, 19:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111699
-
Stefan Bürk abandoned the change 10/19/26, 20:38
-
Alexander Schnitzler commented on patch set 2 10/20/26, 07:54
I had a closer look at the closure question and the backports, since I'd like to pick this up again. Closures The current behaviour on main is not "silently swallowed", only the test setup hides it. With the real `ReflectionService` and `VariableFrontend` on a serializing backend (PHP 8.5), a model with a closure in an attribute or a parameter default value ends in PHP Fatal error: Uncaught Exception: Serialization of 'Closure' is not allowed ... ReflectionService->__destruct() at shutdown, after the response was sent. And since all schemata share one cache entry, a single such class means no schema is cached at all anymore. 14.3 and 13.4 behave the same on PHP 8.5. As PHP 8.5 explicitly allows closures in constant expressions (e.g. `Assert\Callback`), I'd go for option b: keep such a schema in the runtime cache only. - $this->dataCache->set($this->getClassSchemaCacheIdentifier($className), $classSchema); + try { + $this->dataCache->set($this->getClassSchemaCacheIdentifier($className), $classSchema); + } catch (\Exception) { + // A closure in an attribute argument or a parameter default value (PHP 8.5) + // cannot be serialized, such a schema is built again in every process. + } With that, the unit tests and Garvin's functional tests are green locally; the unit tests fail against main's `ReflectionService` as they should. Backports The change does not cherry-pick cleanly to 14.3/13.4 (constructor and unit test differ). I'd keep `$dataCacheNeedsUpdate` and an empty `__destruct()` there, so subclasses calling `parent::__destruct()` don't break. The closure fixtures are PHP 8.5 syntax, so on those branches `lintPhp` and `phpstan` with `-p 8.2` and the functional test fail with "Constant expression contains invalid operations". I'd backport the production change (including the `try`/`catch`, as both branches also run on PHP 8.5) plus the unit tests only, and keep the closure tests on main. On 13.4 the unit test needs `new TransientMemoryBackend('Testing')`. With that, the new unit tests fail on the unpatched branches and pass with the backport on PHP 8.2 and 8.5, and the extbase unit and functional suites (sqlite, PHP 8.5) are green on both branches. @Stefan: the fix itself is good and I think it's worth landing. Would you like to restore the change and carry on with it, or would it be fine with you if I take it over and push the next patch set? -
Garvin Hicking commented on patch set 2 10/20/26, 08:02
Reply
+1 on Alexanders assessment, I also don't think we should abandon this. I am sorry if my comments suggested this was what I was going for (I was not; I merely wanted to discuss/point out). -
Stefan Bürk commented on patch set 2 10/21/26, 03:12
Reply
I abandoned the change because the closure thing is a completly dedicated issue and **should** be handled within it's own issue and change. Try to deal here with it mixes the concern of the change and mixing stuff up. Using the try/catch simply hides the "non cachable" class schema away, and a developer does not get aware of it that something in a model prevents caching the schema of it. In my eyes, we should not hide that away by catching the exception, and loging is not "hit the developers finger" enough. In my eyes the extra stuff added to **my** change should be extracted into a dedicated change (the test) and instead looked into the ClassSchema building around the "callable" stuff and to proberly handle that - or deal with questions like * Do we need the callable method PHP8.5 syntax stuff or can we throw it away? * **OR** Can it be made serialiuze/unserialze safe ? But that's out of the scope of this change. Combined with this change at least other model schemas are "persistested", but given that soem developer may use that in most of there models in some way would mean that the persisted cache gets pretty obsolete. I leave it to you both how to contine -- reenable the change and extract the stuff into a own handling or not. Maybe "class" schema should evaluate if it can be serialized (cached) or not - but that would also rule out backends not serializing/unserializing. But again, thats schema realated and should be it's own handling branch. Note: Adding the try-catch here leads that noone is going to fix that because it is hidden away (until somewone removes the try-catch here). That can and should be not the solution for the PHP8.5 callable stuff. The scope of my change was the service and cache handling within the __destruct(), and not fixing PHP8.5 syntax suger issues within the schema building/handling. From my side -1 on the try-catch and -1 on addign the unrelated test-case for another issue to this change, thus the abandoning of it. I do not give my name for a change adding the try-catch, because I personally do not take that as a solution for the unrelated throwen in issue here. Garvin should be able to un-abandon the change, but if the the conses is to use try-catch than please go ahead, create a additional issue for it, push the change as a new change with 2 resolve lines - okay ... that does not resolve the php8.5 callback issue anyway. If try-catch than only to throw a concrete exception with a TYPO3 Exceoption Code - but not swallowing the exception. -
Alexander Schnitzler commented on patch set 2 10/21/26, 06:46
Reply Unresolved
Thanks Stefan, understood. Splitting the closure topic into its own issue makes sense to me. For the record, the behaviour with and without the `try`/`catch`, on PHP 8.5 with a serializing cache backend and a model that has a closure in an attribute argument or a parameter default value: * main today: the schema is built, the response is sent, then `ReflectionService->__destruct()` ends in "Serialization of 'Closure' is not allowed" at shutdown. Since all schemata share one cache entry, no schema is cached at all anymore. * PS1 (no `try`/`catch`): the exception is thrown during the request, when the schema is built, so the request fails. Other schemata are cached. * with `try`/`catch`: the request succeeds, the schema is only kept in the runtime cache and rebuilt in every process, without any notice. 14.3 and 13.4 behave like main on PHP 8.5, so a backport of PS1 turns the fatal at shutdown into a failing request there. Hence the `try`/`catch` idea. It's safe to backport; on main we could instantly move forward into a different direction. On your question whether it can be made serialize/unserialize safe: I don't see a way from the outside, only within `ClassSchema` itself via `__serialize()`/`__unserialize()`. Closures end up in the schema through `Validate` and `FileUpload` attribute instances (`newInstance()`) and parameter default values (`getDefaultValue()`). Simply filtering them out would make a cached schema differ from a freshly built one (e.g. a validator losing its callback). But since closures in constant expressions are static, `__serialize()` could store where they come from (class, method/property, parameter, attribute) and `__unserialize()` could restore them via reflection. That would also cover first-class callables like `strlen(...)`.
Unresolved