I'm occassionally running into the following fatal error in actions.inc:

PHP Fatal error:  Cannot use object of type DatabaseStatementBase as array in \d7-patch\includes\actions.inc on line 85

Reviewing the code, it looks like the $result-variable (array) is being overwritten by the result of a call to $query->execute().

Patch attached changes the name of the database-result variable to avoid this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dries’s picture

It is quite standard to use $result for the result of the query. Maybe we can rename the other result?

mr.baileys’s picture

Sure, that would work too. I changed the query result variable because it was added last, and because it was only used twice.
Attached is a patch using $result for the query result and $actions_result to store the result of action function callbacks.

catch’s picture

Status: Needs review » Reviewed & tested by the community

Tests pass, new variable name seems fine.

mr.baileys’s picture

@catch: your comment ("tests pass") leads me to wonder if this patch should include tests, since the tests also passed before applying this patch, yet there was a bug. Or should another issue be opened to request more tests for actions?

catch’s picture

Status: Reviewed & tested by the community » Needs review

That's a good point, we should probably add tests here.

Status: Needs review » Needs work

The last submitted patch failed testing.

andypost’s picture

To write test-case here should be an action so where to put it? maybe actions_test.module against actions.inc

andypost’s picture

Another test was added #246096: Cron triggers are not executed

But testing bot still say "tests pass" ... because error happens only if $action_ids is array and Ids are numbers.

So trying to write test...

andypost’s picture

Assigned: Unassigned » andypost
Status: Needs work » Needs review
FileSize
7.08 KB

So here complex patch.

1) actions.inc fixed from #2
2) added tests to configurable actions, provided as part of trigger_test

Logic for test:
1) create non configurable action and assign on trigger cron run (already was)

2) create 2 implementations of configurable actions (same as "Send mail" but just with subject, increment variable)
3) Assign both to cron run trigger

4) run cron

5) check variables (should be changed in actions)

Patch needs corrections in code comments...

Berdir’s picture

A few minor comment improvements..

+   * Assign an actions to a trigger, then pull the trigger, and make sure the actions fire.

The "an" isn't necessary anymore..

+    // Select this test action and assign it to a cron run trigger.

Hm.. I'd say, Select *the* test action....

+    // Make a copy of action with different description.

Now action is singular again, so... ".. of *an* action with.."

+    // Make sure the non-configurable action fire.

singular again, so... "action fire*s*".

+ * Implementation of a configurable Drupal action.

I think these should simply be "Implement a configurable..." now.

I can also confirm that the tests fail without the changes in actions.inc, with the following fatal error:

An error occurred.
Path: /batch?id=4&op=do
Message:
Fatal error: Cannot use object of type DatabaseStatementBase as array in /home/berdir/workspace/drupal7/includes/actions.inc on line 89
Berdir’s picture

Status: Needs review » Needs work
andypost’s picture

Status: Needs work » Needs review
FileSize
7.08 KB

Berdir, many thanks!
Reroll

andypost’s picture

FileSize
7.08 KB

plural *have fired*

mr.baileys’s picture

2 really minor comments:

  1. + * Return a form definition so the Cron test configurable action can be configured.
    No capital required on 'cron'.
  2. + // Make a copy of an action with different description.
    Should read "...with a different..."

... and one bigger concern: the new tests are located in the TriggerCronTestCase test case, and a lot of the comments contain references to cron. To me, this implies that we are testing how configurable actions behave when triggered by a cron run. This test however is not about cron. It's about testing configurable actions (and making sure the bug which this issue is about doesn't re-occur). IMHO, it would be cleaner to seperate this into its own test case (TriggerConfigurableActionsTestCase?). This separate test case could still use the cron trigger for testing, but it would be more clear what is being tested.

Just my 2 cents though, others might disagree...

andypost’s picture

FileSize
7.09 KB

Comments fixed, tnx mr.baileys

About concern:

As i research how to make a test I found that we need case when actions_do() receive array of aids and minimum one of them should be configured. All current _trigger_user() _trigger_node() _trigger_comment() executes with ONLY one aid so using this triggers is not possible to catch this bug.

New cron trigger use actions_do with array - so this trigger is Only possible to test actions_do() with array of aids

And because tests are using only one possible trigger (cron) they placed near trigger module

andypost’s picture

FileSize
6.96 KB

reroll to track HEAD

andypost’s picture

FileSize
6.95 KB

fixed comment

- Return a form definition so the cron test configurable action can be configured.
+ Return a form so the cron test configurable action can be configured.
chx’s picture

Status: Needs review » Reviewed & tested by the community
webchick’s picture

I worked with andypost to revise some of the comments in the test function. New patch coming shortly.

andypost’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
6.96 KB

Many thanks to webchick!!!

reroll with laconic comments

andypost’s picture

FileSize
6.93 KB

removed useless 254 limit at testing action

webchick’s picture

Status: Needs review » Fixed

Great job. :) Committed to HEAD!

Status: Fixed » Closed (fixed)

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

andypost’s picture

Status: Closed (fixed) » Needs work

sqlite does not have md5() function so this breaks sqlite tests #503794: Tesing results for pgsql and sqlite

chx’s picture

Status: Needs work » Needs review
FileSize
762 bytes

Fixing that is not hard.

webchick’s picture

Status: Needs review » Fixed

Well that was easy. :)

Status: Fixed » Closed (fixed)
Issue tags: -Quick fix, -actions

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