I created a rule with a condition nodeisoftype and action as print a systemmessage, the event was on update of content

when i tried to update a node of content type as specified in the condition, the action did not fire. i debugged and saw that i had given the content type name in capitals , 1. so i tried to edit the condition and save, upon debug still the old condition was being picked up
2. tried deleting the rule and created another, same thing happened now also, old condition was picked up

3. i tried to clear cache , the event didnt even get dispatched now.

This seems to be a major issue!

When i tried to delete the rule and created an other rule after clearing cache, i got another weird error on updating the content

TypeError: Argument 1 passed to Drupal\rules\Plugin\Condition\NodeIsOfType::doEvaluate() must implement interface Drupal\node\NodeInterface, string given in Drupal\rules\Plugin\Condition\NodeIsOfType->doEvaluate() (line 40 of modules/contrib/rules/src/Plugin/Condition/NodeIsOfType.php)

Comments

sukanya.ramakrishnan created an issue. See original summary.

sukanya.ramakrishnan’s picture

To add an update, if i create everything properly the first time around, the rule works fine, but any updates or corrections dont work at all..

i was able to work through the php error by using the data selector instead of typing the value as node for for the nodeisoftype condition.!

sukanya.ramakrishnan’s picture

Update: There is still a need for a cache clear to be done if a rule is changed , but event is dispatched properly upon cache clear (Issue #3 no longer exists)

fago’s picture

Title: Rule not working - cache issue maybe? » Cache is not invalidated when Rules are changed
Category: Bug report » Task
Priority: Major » Critical

Yes, I also noted this. Looks like the cache entries are not cleared when a rule is updated. We should add some test coverage for this also.

I think the case of add/removing events is handled, but it is not handled when just some other changes are made.

sukanya.ramakrishnan’s picture

Thanks fago, I also noticed one more issue related to cache! when i create a component, i have to clear the cache for the component to appear on the actions dropdown. Is that working as designed?

Thanks,
Sukanya

fago’s picture

>when i create a component, i have to clear the cache for the component to appear on the actions dropdown. Is that working as designed?

No, of course not. You should never have to manually clear the cache. Could you file another issue for that? Thanks!

sukanya.ramakrishnan’s picture

Never mind, the issue reported in #5 does not occur. must have been an oversight on my part!

samuel.mortenson’s picture

Looking into this a little bit - since Rules cache is by event, would the appropriate fix be to invalidate all cache entries that start with the Event which triggers a given Rule?

For example, we would invalidate cache when editing a Rule triggered by the "After saving new content" event by clearing all cache IDs that match "rules_event:rules_entity_insert:node:*".

Am I understanding this correctly?

promo-il’s picture

I use in mysql
TRUNCATE `cache_rules`;

Syntapse’s picture

Im building with Drupal 8.7.8 and refreshing cache on every single small change to Rules to make it work. Is there a fix for this in the pipeline or is it by design? thanks.

tr’s picture

Issue tags: +beta blocker
jonathan1055’s picture

Status: Active » Needs review
StatusFileSize
new803 bytes

I have done some work on this, based on samuel.mortenson's comments in #8

This patch demonstrates the problem, by removing the drupal_flush_all_caches(); in the configureAndExecute test. This should fail.

Status: Needs review » Needs work
jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new2.26 KB

Here is the same change to the test as per #12 with the new changes to set a tag when the cache is saved (e.g. after doing something that reacted to a rules event), and invalidate the tag when the rule is changed. The tag is simply the rules event id, for example 'rules_entity_presave:node' or 'rules_entity_update:node--article'.

This patch clashes with my other one in #3108494-16: Exception when updating cache with empty data but the actual fix is independent. So which ever of these is committed first, the other will need re-rolling.

bmunslow’s picture

Hi @jonathan1055,

Thanks for your work on this issue.

It turns out #3108494-16 has already been commited to dev, so, as you mentioned, #14 doesn't apply any longer.

I re-rolled your patch for latest dev, please find it attached.

jonathan1055’s picture

Thanks for the re-roll @bmunslow. I am adding further test coverage for this fix.
If any else of the 21 followers would like to test this manually, please do :-)

bmunslow’s picture

Hi @jonathan1055!

I've manually tested this patch quite thoroughly in a current project and I can confirm it has fixed all caching issue for good in my case.

jonathan1055’s picture

StatusFileSize
new9.15 KB

Here is a patch with a new test to cover the addition of two rules both reacting on the same event. This has the initial fix as included in #14/15 but I also discovered that when deleting a rule and another rule is still active with the same event then the cache for the events should also be invalidated. This is simple to fix, but here is the new test without this, so the patch will fail.

jonathan1055’s picture

StatusFileSize
new9.1 KB

Error in patch, test aborted. Patch #19 should fail properly

Status: Needs review » Needs work
jonathan1055’s picture

Status: Needs work » Needs review
StatusFileSize
new9.65 KB
new764 bytes

As expected, the test fails after deleting Rule 1 but leaving Rule 2 active.

Patch #21 includes the fix to ReactionRuleStorage::delete which is very similar to the fix in ::save

Forgot to say in #18 that I have added a new function clickLinkByHref() into RulesBrowserTestBase which finds a link matching a partial href via xpath. This makes it easier to use the enable and disable links/buttons in the test.

tr’s picture

Error in patch, test aborted.

Actually the patch was fine - I triggered a retest and it ran as expected. Aborts are usually due to transient testbot infrastructure fails - can't find database and things like that. A retest usually works.

I'll get committed #21 later today.

jonathan1055’s picture

Error in patch, test aborted.

What I meant was that I made an error in creating that patch, and I aborted the test manually. I wondered why it was run again later.

I'll get committed #21 later today.

Excellent, thatnk you.

  • TR committed 54f865a on 8.x-3.x authored by jonathan1055
    Issue #2769511 by jonathan1055: Cache is not invalidated when Rules are...
tr’s picture

Status: Needs review » Fixed

This is a very nice solution to a long-standing problem. Thanks! Committed patch #21.

jonathan1055’s picture

Thanks, yes the solution was nice and neat.

Following the recent addition of extra tests in this issue and in
#3110461: Add rules_ban actions and conditions to functional tests
#3108494: Exception when updating cache with empty data and
#3104328: Move list builders from D8RE into Rules please could you commit this patch to increase the number of allowed deprecations in Travis builds. I thought I would wait until there were several issues that changed the totals before making the patch. Keeping these numbers accurate is a good way to for me to be alerted to any new @trigger_error deprecations, which I will then report on #3089502: [meta] Rules deprecated code

tr’s picture

Sure, I can commit this, but can you put the patch in the deprecation issue where we've been handling this?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.