Action 'Publish a content item' not working

Created on 25 April 2023, over 1 year ago
Updated 24 November 2023, 12 months ago

Problem/Motivation

Action 'Publish a content item' not working. Whitescreens when run.
In logs generates a Node error reading: Drupal\Core\Entity\EntityStorageException: Update existing 'node' entity revision while changing the revision ID is not supported. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 815 of /code/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php)

Steps to reproduce

I used a simple rule that reacted on "After updating a content item entity" and had action "Publish a content item" to work on 'node'

uuid: 620d91fb-ece9-4c1a-a721-24f5bc060907
langcode: en
status: true
dependencies: {  }
id: update
label: update
events:
  -
    event_name: 'rules_entity_update:node'
description: ''
tags: {  }
config_version: '3'
expression:
  id: rules_rule
  uuid: ce666edb-fc92-494c-ad67-cd99a1c57745
  weight: 0
  conditions:
    id: rules_and
    uuid: 91ca9648-520c-40fe-8f7e-9bbcd445ea20
    weight: 0
    conditions: {  }
  actions:
    id: rules_action_set
    uuid: af752002-fe82-4392-871f-51b2ac448db0
    weight: 0
    actions:
      -
        id: rules_action
        uuid: 9194b900-79c7-4767-b8c5-ac8cb2a8ed45
        weight: 0
        action_id: rules_node_publish
        context_values: {  }
        context_mapping:
          node: node
        context_processors: {  }
        provides_mapping: {  }
πŸ› Bug report
Status

Closed: works as designed

Version

3.0

Component

Actions

Created by

πŸ‡ΊπŸ‡ΈUnited States timb

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

Comments & Activities

  • Issue created by @timb
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    The action is working.

    The reason you see that error, "Update existing 'node' entity revision while changing the revision ID is not supported.", is because you have entity revisions enabled for that content type and you are trying to modify the existing revision "node" while you're in the process of creating a new revision.

    It is a known issue that the UI does not prevent you from making mistakes like this, but even if the UI told you you couldn't do it you would still have to understand the core Drupal entity lifecycle in order to accomplish what you're trying to do.

    Short answer is you need to choose an appropriate event at all times, but particularly in the case where you acting on a specific piece of content being modified and are then trying to modify that same specific content again during the update process.

    In this case, the "After update" event corresponds to the core Drupal hook hook_entity_update()
    The documentation for that hook says:

    Respond to updates to an entity.

    This hook runs once the entity storage has been updated. Note that hook implementations may not alter the stored entity data.

    (where I have added the emphasis).

    So in your use case, I think a more appropriate event is "Before saving a content item", because the node *can* be altered before you enter the saving phase of the lifecycle.

  • πŸ‡ΊπŸ‡ΈUnited States timb

    Thank you @tr I will give it a try with the new event.

  • πŸ‡ΊπŸ‡ΈUnited States timb

    I reset the rule as suggested above as and have now encountered memory errors:

    EVENT: Before saving a content item
    ACTION: Publish a content item (Parameters: node: node)

    Page white screens with:
    Fatal error: Allowed memory size of 268435456 bytes exhausted

    In the error logs:
    Deprecated function: Return type of Drupal\rules\Engine\ActionExpressionContainer::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include() (line 13 of /code/web/modules/contrib/rules/src/Engine/ActionExpressionContainer.php)

    This also occurs with the other default Content actions such as Unpublish and Make selected content sticky.

    This is both w/ and w/o revisions on the node.

    This occurs in both the alpha and dev version of module.

  • Status changed to Closed: works as designed 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    That error is because you are using PHP 8.1, and Rules was made compatible with PHP 8.1 years ago shortly after Drupal core was fixed for PHP 8.1. This tells me you're not using the current version of Rules.

Production build 0.71.5 2024