Issue Bug Closed

#109683Undefined variable "tree" in Expression Language crashes DataHandler during CLI operations on orphaned records

Stefan Froemken 04/22/26, 09:07 updated 08/11/26, 08:46

Description

Hello,

When using the TYPO3 DataHandler within a CLI context (e.g., an UpgradeWizard), processing records that are orphaned or reside on non-existent pages leads to a fatal error in the Symfony Expression Language parser. This occurs because the tree object is only initialized if a rootline is successfully determined.

This issue is specifically present when using the global Configuration/page.tsconfig file, as the condition matching logic there does not gracefully handle the absence of the tree variable.

Reproducer

  1. Define a Page TSconfig condition in Configuration/page.tsconfig:
[916 in tree.rootLineIds]
  TCEMAIN.clearCacheCmd = 12
[END]
  1. Execute a DataHandler operation via CLI (e.g., an UpgradeWizard) on a record whose pid does not exist.
  2. The Symfony Expression Language parser fails because tree is completely missing from the context.

Current Behavior

The parser stops with the following error:

Variable "tree" is not valid around position 1 for expression "916 in tree.rootLineIds".

Because the variable is not registered at all when the rootline is empty, standard null-coalescing (tree ?? …) or optional chaining (tree?.) within the expression does not prevent the crash. This is due to the Symfony Expression Language being evaluated in a mode where unknown variables are not ignored:

if (!($this->flags & self::IGNORE_UNKNOWN_VARIABLES)) { ... }

The only current workaround is a complex and non-intuitive expression:

[916 in traverse((tree ?? {rootLineIds: []}), 'rootLineIds')]

Affected Component

The logic resides in IncludeTreeConditionMatcherVisitor.

The current implementation only adds tree to $enrichedVariables if $localRootLine is not empty:

$localRootLine = $variables['localRootLine'] ?? $fullRootLine;
if (!empty($localRootLine)) {
    $tree = new \stdClass();
    // ... initialization of $tree
    $enrichedVariables['tree'] = $tree;
}

Expected Behavior

The tree variable should be initialized as an empty object or a null-safe entity by the IncludeTreeConditionMatcherVisitor even in CLI or orphaned record contexts. This would allow the use of the null-safe operator (tree?.rootLineIds) or simply return false for the condition without crashing the process.

Stefan

Reviews 2