Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#25 | sqlite_md5.patch | 762 bytes | chx |
#21 | actions-tests2-D7.patch | 6.93 KB | andypost |
#20 | actions-tests2-D7.patch | 6.96 KB | andypost |
#17 | actions-tests-D7.patch | 6.95 KB | andypost |
#16 | actions-tests-D7.patch | 6.96 KB | andypost |
Comments
Comment #1
Dries CreditAttribution: Dries commentedIt is quite standard to use $result for the result of the query. Maybe we can rename the other result?
Comment #2
mr.baileysSure, 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.
Comment #3
catchTests pass, new variable name seems fine.
Comment #4
mr.baileys@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?
Comment #5
catchThat's a good point, we should probably add tests here.
Comment #7
andypostTo write test-case here should be an action so where to put it? maybe actions_test.module against actions.inc
Comment #8
andypostAnother 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...
Comment #9
andypostSo 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...
Comment #10
BerdirA few minor comment improvements..
The "an" isn't necessary anymore..
Hm.. I'd say, Select *the* test action....
Now action is singular again, so... ".. of *an* action with.."
singular again, so... "action fire*s*".
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:
Comment #11
BerdirComment #12
andypostBerdir, many thanks!
Reroll
Comment #13
andypostplural *have fired*
Comment #14
mr.baileys2 really minor comments:
+ * Return a form definition so the Cron test configurable action can be configured.
No capital required on 'cron'.
+ // 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...
Comment #15
andypostComments 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 aidsAnd because tests are using only one possible trigger (cron) they placed near trigger module
Comment #16
andypostreroll to track HEAD
Comment #17
andypostfixed comment
Comment #18
chx CreditAttribution: chx commentedComment #19
webchickI worked with andypost to revise some of the comments in the test function. New patch coming shortly.
Comment #20
andypostMany thanks to webchick!!!
reroll with laconic comments
Comment #21
andypostremoved useless 254 limit at testing action
Comment #22
webchickGreat job. :) Committed to HEAD!
Comment #24
andypostsqlite does not have md5() function so this breaks sqlite tests #503794: Tesing results for pgsql and sqlite
Comment #25
chx CreditAttribution: chx commentedFixing that is not hard.
Comment #26
webchickWell that was easy. :)