After deleting a flagged entity from my site using the Drupal API, I am getting the php error below when an outdated / cached search engine link is used to access the entity:
Request URI: https://my-site.com/ca/flag/flag/wishlist/35598
Notice: Trying to get property of non-object in flag_entity->applies_to_entity() (line 131 of /var/www/company_xxx/html/sites/all/modules/contrib/flag/includes/flag/flag_entity.inc).
I understand that the entity no longer exists, and that the url being used is invalid, but I wish the Flag module could better handle these situations without having to throw a php error.
See patch below which I created to fix this bug. If you are getting the same error message, I hope this helps.
Comment | File | Size | Author |
---|---|---|---|
#14 | 2839047-property-non-object-flag-entity-14-D7.patch | 1.44 KB | somersoft |
| |||
#11 | 2839047-property-non-object-flag-entity-3.patch | 1.91 KB | gturnbull |
#7 | 2839047-property-non-object-flag-entity-2.patch | 1.1 KB | gturnbull |
| |||
#2 | 2839047-property-non-object-flag-entity.patch | 1.24 KB | gturnbull |
Comments
Comment #2
gturnbull CreditAttribution: gturnbull commentedComment #3
gturnbull CreditAttribution: gturnbull commentedComment #4
gturnbull CreditAttribution: gturnbull commentedComment #5
gturnbull CreditAttribution: gturnbull commentedComment #7
gturnbull CreditAttribution: gturnbull commentedComment #8
gturnbull CreditAttribution: gturnbull commentedComment #9
joachim CreditAttribution: joachim as a volunteer commentedGood catch, and thanks for working on a patch for this.
We don't need to be as wordy here. There's no need to say 'deleted by the Drupal API'; just 'deleted' will do!
And a simpler example than yours is a flag link that's out of date -- user A can load a page with a link to flag a node, and user B can delete that node between that and user A clicking the flag link.
Also, please remember to wrap comments to 80 chars.
I'd rather we check is_null(), as that's what fetch_entity() returns when no entity can be loaded, and also if we made this check separately rather than nesting if()s.
Lastly, please please please don't tag issues before reading about how to use the tags on issues! They are not for repeating the title, or for random keywords!
Comment #10
gturnbull CreditAttribution: gturnbull commentedHi joachim,
Thanks for taking the time to review my bug report and associated patch. Your comments and feedback are greatly appreciated.
I'm out of the office this week, but will update, test, and post a revised version of my patch early next week.
Thanks again.
Gordon
Comment #11
gturnbull CreditAttribution: gturnbull commentedComment #12
gturnbull CreditAttribution: gturnbull commentedComment #14
somersoft CreditAttribution: somersoft commentedPatch recreated.
Comment #15
web226 CreditAttribution: web226 commentedThanks @somersoft the patch in #14 worked for me with Drupal 7.65, Flag 7.x-3.9 and PHP 7.2