Skip to content

[DOCS] Document container compilation pitfalls for extended classes - #54

Merged
garbast merged 1 commit into
evoWeb:developfrom
sfroemkenjw:docs/container-compilation-pitfalls
Nov 25, 2026
Merged

garbast merged 1 commit into
evoWeb:developfrom
sfroemkenjw:docs/container-compilation-pitfalls

Conversation

@sfroemkenjw

Copy link
Copy Markdown
Contributor

Context

This follows #53 (class loader rebuilds a proxy file removed by a concurrent cache flush). After we deployed that fix, the same TypeError showed up again in production. The main cause turned out to be something else. It is a configuration topic, so this PR documents it.

Root cause

Extender's class loader is registered only when the EventDispatcher is instantiated. That happens after the DI container exists. Container compilation runs before that point.

If the service definition of the extending class inherits autowire/autoconfigure from _defaults, Symfony reflects the class during compilation (RegisterAutoconfigureAttributesPass, AutowirePass). Excluding Domain/Model from the resource scan does not help here because the tag requires an explicit definition. Reflecting the extending class makes Composer autoload the base class. From then on, that process works with the original class and none of the extending code.

There is a second case. If the extended extension registers the base class as a public service, the PhpDumper loads it while dumping the container (class lineage for preloading). EXT:events2 does this with its Event model for its own tests.

Consequences

Problems start when the compiling process is a frontend request that uses Extbase with the affected model. ClassSchema and DataMap are then built from the base class. The DataMap lands in the shared Extbase cache, and later requests run into missing properties or this error:

DataMapper::thawObjectProperty(): Return value must be of type ?object, array returned

The compiling request itself fails with "Call to undefined method" on a method of the extending class.

Documented fixes

  • Extending class: set autowire: false and autoconfigure: false on its service definition.
  • Base class registered as public service by the extended extension: override it in the extending extension (loaded after the extended one) with public: false, autowire: false and autoconfigure: false.

Cache flush notes

A backend flush via the Maintenance module is usually less of a problem. The editor's next backend request rebuilds the container. The timing is favorable, but nothing guarantees it.

typo3 cache:flush on the CLI leaves no container until cache:warmup has finished. Concurrent frontend requests compile it themselves because there is no lock. The docs now recommend running flush and warmup for the new release before switching the release symlink. They also mention the caveat about caches that contain absolute or real paths.

Changes

Only Documentation/Configuration/Index.rst is touched. The page is now split into three sections:

  1. Register the extending class
  2. Prevent loading the base class during container compilation
    • Extending class reflected by Symfony
    • Extended extension registers base class as public service
    • Consequences
  3. Cache flushes and concurrent requests

It renders without warnings via Build/Scripts/runTests.sh -s checkRstRenderingSingle.

Verification

We tested this in a TYPO3 13.4 project with events2. Without the configuration, we did a full cache flush and then requested an event detail page. That first frontend request compiled the container and failed with HTTP 500 (undefined method of the extending class). With the configuration in place, all extended classes came from the extender proxy cache, including in the compiling process.

Extender could possibly handle this in code later (for example with a compiler pass), but this PR only documents the behaviour.

🤖 Generated with Claude Code

Explain why extended classes can be loaded as base classes while the
DI container is compiled. Document the required service configuration
and add notes on cache flushes and concurrent requests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@garbast
garbast merged commit 137cd31 into evoWeb:develop Nov 25, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants