If you create a user flag and try to use "User is flagged" as a condition in a rule an error is thrown:
Notice: Trying to get property of non-object in flag_rules_condition_flagged() (line 399 of /Users/creynder/Dropbox/Work/Research/Drupal/drupal-7.x/sites/all/modules/flag/flag.rules.inc).
And the rule action is not executed.
The error is thrown in the flag_rules_condition_flagged
method.
After a little debugging I found out the the 3rd parameter ($account
) does not receive a user object, but an array containing 2 keys:
flag
and user:select
. See att. for dsm dump.
The 2nd parameter $entity
however does receive the correct user object.
This rule condition does work as it should with node flags.
Comment | File | Size | Author |
---|---|---|---|
#12 | 2015-05-15 16-31-59.png | 74.97 KB | stBorchert |
#10 | condition_flagged_empty_account-1610172-10.patch | 514 bytes | stBorchert |
#6 | 1610172-6.patch | 477 bytes | shabana.navas |
Screen shot 2012-05-31 at 11.01.14.png | 26.81 KB | creynders |
Comments
Comment #1
tbenice CreditAttribution: tbenice commentedhaving the same issue.
Comment #2
c.breschkow CreditAttribution: c.breschkow commentedsame for me
Comment #3
c.breschkow CreditAttribution: c.breschkow commentedI changed the line 399
from: return $flag->is_flagged($flag->get_content_id($entity), $account->uid); in return $flag->is_flagged($flag->get_content_id($entity), $account);.
Idon't know if this is the right way, but it works for me.
Comment #4
joachim CreditAttribution: joachim commentedAny chance you could post that as a patch please?
Comment #5
joachim CreditAttribution: joachim commentedUpping version; will need backport.
Comment #6
shabana.navas CreditAttribution: shabana.navas commentedPatch against version 7.x-3.x is submitted below.
Comment #7
shabana.navas CreditAttribution: shabana.navas commentedComment #8
joachim CreditAttribution: joachim commentedThanks for the patch!
Setting to 'needs review' so other users know this needs trying out.
Comment #9
shabana.navas CreditAttribution: shabana.navas commentedFor some reason, I cannot replicate this problem without the patch. Anyone else getting this error still?
Comment #10
stBorchertHey.
This seems still valid as we are getting this error reproducible on a commerce-site after anonymous users finalize the checkout.
The problem is,
$account
is "0" in flag_rules_condition_flagged() so we need to check this first.$flag->is_flagged()
requires a user ID so handing a full user object to it will obviously break later.Comment #11
joachim CreditAttribution: joachim commented> The problem is, $account is "0" in flag_rules_condition_flagged() so we need to check this first. $flag->is_flagged() requires a user ID so handing a full user object to it will obviously break later.
Can you explain a bit more please?
Are you saying that the Rules callback sometimes gets an $account object, and sometimes a number 0?
Comment #12
stBorchertJup, exactly. As far as I remember this happens only for anonymous users on finalizing the checkout process.
Without the patch you will get an error in
flag_rules_condition_flagged()
since$account
is not an always object.We had a rule setting the status of orders flagged with "Order paid" to "completed". The problem is caused by a condition that checks if the order is flagged (see attached picture).
Comment #13
joachim CreditAttribution: joachim commented> As far as I remember this happens only for anonymous users on finalizing the checkout process.
ONLY when finalizing the checkout process? Have you tried for anon users at other times? Because if you mean that it's only at that time, that smells like a bug in Commerce...
Comment #14
joachim CreditAttribution: joachim commentedI'm going to set this to needs work, as it seems like the cause of this isn't properly understood.
Comment #15
gaurav.bajpai CreditAttribution: gaurav.bajpai as a volunteer and at Faichi Solutions Pvt Ltd commentedComment #16
gaurav.bajpai CreditAttribution: gaurav.bajpai as a volunteer and at Faichi Solutions Pvt Ltd commentedComment #17
anup.singh CreditAttribution: anup.singh as a volunteer and at Faichi Solutions Pvt Ltd for Faichi Solutions Pvt Ltd commentedWith latest version of flag and Drupal core , I have tried reproducing this issue but didn't had any success.
Steps followed.
1. created a User flag
2. Created a rule having condition as "A user has been flagged" and action as "Send mail".
3. on click of flag in user page there is no issue, also mail is successfully triggered.
For now I am "Closed (cannot reproduce)" , please reopen in case its reproducible with detailed steps.
Thanks