I keep seeing this error when trying to access the triggered rules page. This bug is also in your latest dev code (I checked). It may be happening only in certain configurations. Non-the-less the problem is in the rules module. It is occurring because of an element "#weight" parameter being interpreted as a string instead of an int (or other numerical type). So it doesn't like it.

Anyway, I have a fix for you.

On line 348 of rules.module replace this:
$element[$key]['#weight'] += $count / 1000;

With this:
$element[$key]['#weight'] = (int) $element[$key]['#weight'] + ($count / 1000);

And problem solved.

Comments

patrick.thurmond@gmail.com’s picture

Component: Rules Core » Rules Engine
StatusFileSize
new496 bytes

Here is the patch file.

patrick.thurmond@gmail.com’s picture

Status: Patch (to be ported) » Needs review

Status: Needs review » Needs work

The last submitted patch, 1164220_rules.module.patch, failed testing.

patrick.thurmond@gmail.com’s picture

I will try again later today when I have more free time. May have to research this patching thing a bit more.

kanani’s picture

Getting the same error which persists when I make the changes suggested in OP. However eliminating line 346 entirely fixes the issue. so:

foreach (element_children($element) as $key) {
    $element[$key] += array('#weight' => 0);
    $element[$key]['#weight'] += $count / 1000;
    $count++;
  }

becomes

foreach (element_children($element) as $key) {
    $element[$key]['#weight'] += $count / 1000;
    $count++;
  }

Not sure what that line is needed for anyway, as this $element[$key]['#weight'] += $count / 1000; will add #weight to the $element array if it doesn't already exist and will update it if it does.

kanani’s picture

Status: Needs work » Needs review
StatusFileSize
new431 bytes

Patch for #5 attached.

Status: Needs review » Needs work

The last submitted patch, Unsupported-operand-types-1164220-5.patch, failed testing.

patrick.thurmond@gmail.com’s picture

Status: Needs work » Needs review

I was able to apply kanani's patch just fine using the instructions in Drupal.org's documentation. I don't know why are patches are failing other than a problem with the automated testing.

fago’s picture

Status: Needs review » Postponed (maintainer needs more info)

The test-bot is currently broken.

-    $element[$key] += array('#weight' => 0);

We need that line to initialize #weight if it's not set yet. If this is the source of the error message, most likely $element[$key] is not an array for you?

patrick.thurmond@gmail.com’s picture

The first patch simply forces the value to be an integer in any case and that fixed it. I think kanani was trying to simply it as well, but his approach may have introduced a new problem. Simple type casting will resolve the issue.

thedavidmeister’s picture

Type casting seems to be the right way to go about this.

I'm seeing this error when the value of my $element[$key]['#weight'] is a string. Perhaps I achieved these string weights by importing/exporting rules through features, or maybe my rules were created with a legacy version of Rules, who knows...

Point is that the suggestion of the OP resolves a fatal error that appeared without warning on a production site of mine without me changing any relevant code other than pushing/reverting Features.

Type casting the weight from a string to an integer should not cause any problems.

I am using Rules 6.x-1.4

thedavidmeister’s picture

Status: Postponed (maintainer needs more info) » Needs review

Status: Needs review » Needs work

The last submitted patch, Unsupported-operand-types-1164220-5.patch, failed testing.

thedavidmeister’s picture

StatusFileSize
new558 bytes

patch #1 re-rolled against 6.x-1.4 attached

thedavidmeister’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1164220-fix-fatal-error-14.patch, failed testing.

thedavidmeister’s picture

Status: Needs work » Needs review
StatusFileSize
new558 bytes

trying to get test bot to work..

Status: Needs review » Needs work

The last submitted patch, 1164220-fix-fatal-error-14.patch, failed testing.

thedavidmeister’s picture

Status: Needs work » Needs review
StatusFileSize
new554 bytes
thedavidmeister’s picture

yay, test passed! that kind of took too many patches to get such a simple thing right >.<

thedavidmeister’s picture

StatusFileSize
new559 bytes

ahem

thedavidmeister’s picture

Update on this which might help others resolve their errors:

I was having problems getting my rules included in Features to revert at all. I uninstalled rules, manually deleted all rules hooks from my Features then installed the latest dev version of Rules and exported all of my Rules from my production site manually through the UI then re-created the Features.

This caused the fatal errors to go away. Not sure exactly what to make of that, I was previously using Rules 1.4 but it is possible that when the site was first set up an older version of Rules was used and had since been upgraded to latest stable.

TwoMice’s picture

Version: 6.x-1.4 » 6.x-1.x-dev
Component: Rules Engine » Rules Core
StatusFileSize
new493 bytes

This issue persists in 6.x-1.x. Patch from #21 re-rolled for dev branch.

thedavidmeister’s picture

Update: our fatal errors came back in a later release when we re-exported Rules into Features. May have had something to do with git merging and the way that rules seems to "interleave" it's data in arrays rather than having one key-value pair per rule - this makes it very hard for humans to see what's actually getting committed each time Rules are re-exported. Entirely possible that the "bad" data that Rules is using in Features is partly due to us doing something silly in a commit or merge, but we'll probably never know.

Unfortunately we've spent more time debugging this issue than it took to pull Rules out of our system and re-implement everything the "old fashioned" way with simple hooks and API calls.

tr’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

Drupal 6 is no longer supported, and the code in question is different in Drupal 7.