Call to a member function getCacheTags() on null

Created on 27 September 2025, about 1 month ago

I was using drupal/workflow 2.1.7 and all my systems tests were running ok.
When I upgraded drupal/workflow to the dev version on 28.09.2025, I get following error in the system tests:

      Fatal error: Call to a member function getCacheTags() on null

I downgrade drupal/workflow and all is ok again.

The drupal/workflow version I upgraded to is:

            "name": "drupal/workflow",
            "version": "dev-2.1.x",
            "source": {
                "type": "git",
                "url": "https://git.drupalcode.org/project/workflow.git",
                "reference": "ccb40c33dd33590d01139eb6df511f2d157993e7"
            },

I asked an A.I. to investigate. I came back with following:

Fixed WorkflowTransition Entity

File: /www/modules/contrib/workflow/src/Entity/WorkflowTransition.php

Before:

  public function getCacheTagsToInvalidate() {
    $tags = parent::getCacheTagsToInvalidate();
    // Add 'node:NID' as CacheTag, next to 'workflow_transition:HID'.
    $entity = $this->getTargetEntity();
    $tags = Cache::mergeTags($tags, $entity->getCacheTags());
    return $tags;
  }

After:

  public function getCacheTagsToInvalidate() {
    $tags = parent::getCacheTagsToInvalidate();
    // Add 'node:NID' as CacheTag, next to 'workflow_transition:HID'.
    $entity = $this->getTargetEntity();
    if ($entity !== null) {
      $tags = Cache::mergeTags($tags, $entity->getCacheTags());
    }
    return $tags;
  }

And after that fix the error goes away. The fix looks very much ok.

🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024