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

History 513

  1. Stefan Froemken commented <span data-processor="relativetime" data-value="2026-04-22T13:01:39+00:00" > 04/22/26, 13:01 </span>

    Now the complex version is not working in Web Context. Changed it to:

    [916 in (tree ?? {rootLineIds: []}).rootLineIds]
      TCAdefaults.pages.doktype = 15
      TCAdefaults.pages.hidden = 0
    [END]
  2. Christian Kuhn commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-04-23T12:15:08+00:00" > 04/23/26, 12:15 </span>

    Applied in changeset commit:68cea6ff506d4bb75cb958e679b5c0106b212e37.