TypeError: Drupal\rules\Plugin\Condition\NodeIsPublished::doEvaluate(): Argument #1 ($node) must be of type Drupal\node\NodeInterface, null given

Created on 24 November 2023, 10 months ago
Updated 21 July 2024, about 2 months ago

Problem/Motivation

When creating a new context that reacts to the published status of a node, my application crashed entirely and rules needed to be uninstalled via drush for it to come back.

I lost all my contexts that used this condition (previously it worked).

Steps to reproduce

Add a new context that reacts to a node not being published (I haven't tested the other scenario).
Save the context.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

4.0

Component

Rules Core

Created by

πŸ‡ΉπŸ‡­Thailand AlfTheCat

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.

  • Issue created by @AlfTheCat
  • Status changed to Postponed: needs info 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States TR Cascadia

    Please provide information about the Rule you created. The error message is saying that you're trying to test the "published" status on data that is not a node. That implies a configuration error.

    You never have to uninstall Rules if you have a malfunctioning Rule. Rules are configuration entities, so you just need to delete or disable the configuration entity. There are drush commands for Rules that will allow you to do this. Type "drush rules" for a list of commands.

  • πŸ‡ΊπŸ‡ΈUnited States TR Cascadia

    Rules Conditions are not normal Drupal core Conditions and Drupal core does not have a way in the UI to pass context values to Rules Conditions. So what is happening is that you're not passing in the node that the Rules Condition needs to properly operate.

    The "bug" here is that Drupal core should not be giving you the option to use Rules Conditions through the UI - core used to filter Conditions properly but there was a regression introduced a while back the broke this again. I don't know what the status is of the fix for core - I do know there was an issue opened and some patches submitted, but I will have to do some digging to try to find that issue because my initial searches didn't find it.

  • πŸ‡ΊπŸ‡ΈUnited States TR Cascadia

    Some of the background can be found in #2789051: Add schemas for Rules condition plugins β†’ where the claim is that adding a plugin schema for Rules Conditions could help solve this problem, but there are two conflicting (and old) patches in there that no one has reviewed so I don't know if that will be sufficient or whether there are still core changes needed.

  • πŸ‡ΉπŸ‡­Thailand AlfTheCat

    Thanks again for the added info.

    I think there might be some confusion in terminology, I apologize if I'm being unclear. I am referring to the Context module ( https://www.drupal.org/project/context β†’ ) that Rules enhances with additional conditions. In my "steps to reproduce" section of this issue, I meant by adding a context to create a new context at /admin/structure/context. Maybe the bug is on the Context side, but the error message pointed to Rules.

    I dug through my apache error logs and found the full error:

    Uncaught PHP Exception TypeError: "Drupal\\rules\\Plugin\\Condition\\NodeIsPublished::doEvaluate(): Argument #1 ($node) must be of type Drupal\\node\\NodeInterface, null given" at /var/www/***/modules/contrib/rules/src/Plugin/Condition/NodeIsPublished.php line 37

    Hope this helps and thanks again for your attention to this.

  • πŸ‡ΊπŸ‡ΈUnited States TR Cascadia

    Yes I think the Context module must be allowing you to use the Rules conditions just like core does. I did understand what you were saying, but I don't use the Context module myself so I couldn't use that module as an example to illustrate the problem. I think Context is letting you use the Rules conditions but it shouldn't. Just like core is letting you use the Rules conditions in some places (like when configuring block visibility) but it shouldn't. I think the fix is the same for both Context and core - don't let users use the Rules conditions! Core used to prevent Rules conditions from being displayed (that was fixed in #2811519: Blocks do not appear after being placed with the Rules module enabled (or other missing schemata for Condition plugins) β†’ but then got broken again years later).

    I think that #2789051: Add schemas for Rules condition plugins β†’ is probably necessary to prevent core and the Context module from inadvertently using Rules conditions, but I am not sure if it is the only thing that needs to be done. An ideal solution would be something we could do in Rules so that we wouldn't have to "fix" every module that tries to use Conditions.

  • πŸ‡ΉπŸ‡­Thailand AlfTheCat

    Hi TR, thanks for the comprehensive explanation. I understand the issue now. In a way, I guess what I thought was a feature was actually a bug πŸ˜€.

  • Status changed to Active about 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States TR Cascadia
Production build 0.71.5 2024