ISSUE SUMMARY

Using the "Set Data Value" action in Rules to set the created property on a commerce line item entity fails with this fatal error:
ArgumentCountError

TO REPRO

Here is the simplest rule component that reproduces this error:

{ "rules_line_item_argumentcounterror" : {
    "LABEL" : "REPRODUCE Line-Item fatal ArgumentCountError",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "line_item" : { "label" : "Line Item", "type" : "commerce_line_item" },
      "new_date" : { "label" : "New Date", "type" : "date" }
    },
    "ACTION SET" : [
      { "data_set" : { "data" : [ "line-item:created" ], "value" : [ "new-date" ] } }
    ]
  }
}

Steps to reproduce:
- Import this rule component.
- Locate an existing line item ID to use as a test subject. Any line item type/bundle should reproduce this error.
- Execute this rule.
- Enter your test line item ID as the "Line Item" argument.
- Either accept the default date (now) or enter your preferred date for the "New Date" argument. Any valid date should reproduce this error.
- Press Execute.

NOTE

We have a rule in occasional but regular use, and never saw this until after we upgraded to PHP 7.1.

I would tag it PHP71 except now I lack a pre-PHP7 test environment I cannot be sure that is the definitive factor.

Code inspection strongly suggests that this might have been something that PHP 5.6 tolerated, but PHP 7.1's strictness now forbids.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

josephr5000 created an issue. See original summary.

josephr5000’s picture

Issue summary: View changes
josephr5000’s picture

Here's a patch to fix this. Changing status to NEEDS REVIEW.

NOTE ABOUT PRIORITY: I set priority to MAJOR because this gives users a "The site has encountered an unexpected error." which is basically a hard crash. I don't think it is CRITICAL since you can avoid this by not running rules that set commerce-line-item:created, and I haven't yet found any built-in rules in Commerce that run this action. But the action is available and legitimate to use, should work reliably, and should definitely not crash the page.

phdhiren’s picture

Is there any update on the issue, when the patch will be merged?

josephr5000’s picture

@phdhiren: I doubt this will be merged while status remains at NEEDS REVIEW. It needs others to actually try the patch and report their test results. Have you tried it? What success (or lack thereof) did you experience?

rszrama’s picture

Version: 7.x-1.14 » 7.x-1.x-dev
Status: Needs review » Fixed

@josephr5000 I have a ddev env't for testing in different PHP versions. I was able to reproduce the issue easily using the component you provided, which made testing the patch super simple. This works great - thanks for your work those many years ago!

  • rszrama committed 7188fdc on 7.x-1.x authored by josephr5000
    Issue #3021095 by josephr5000: Rules: Set Data Value action on [commerce...

Status: Fixed » Closed (fixed)

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