Problem/Motivation
Originally encountered when debugging an issue with Token reported in https://www.drupal.org/project/token/issues/3574391#comment-16587794
Essentially came to down token checking isset($field_item->$property_name) on an EntityReferenceItem for the property entity.
The code isset($field_item->$property_name) is returning FALSE even though calling $field_item->$property_name correctly returns the Entity.
With @berdir's help I was able to determine this check returned TRUE if I commented out the Fiber suspend in the entity storage base.
I was also able to find that the workaround added for the get magic method in #3565937: Workaround PHP bug with fibers and __get() also fixed when adapted for the isset magic method.
Steps to reproduce
I have only reproduced this on a client site with a wide range on modules and data - have not yet determined the easiest way to reproduce this. Best summary is on related token issue.
Proposed resolution
Implement workaround for isset based on existing workaround for get.
Remaining tasks
Implement test based on __get workaroundImplement workaround for __isset based on workaround for __get- review
User interface changes
N/a
Introduced terminology
N/a
API changes
N/a
Data model changes
N/a
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | core-3590537-11-3590537-workaround-php-bug.patch.diff | 3.57 KB | xurizaemon |
Issue fork drupal-3590537
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
ericgsmith commentedComment #4
ericgsmith commentedComment #5
ericgsmith commentedComment #7
xurizaemonI've tested the fix and tests only with 11.3.x locally. Tests fail for me without Eric's change, and pass for me with it.
My understanding from https://github.com/php/php-src/issues/14983 and https://3v4l.org/ju5mp is that results (for now) are the same with PHP to 8.5, I just didn't have time to deal with environment issues to test locally against main with core@main / PHP 8.5 😬
Comment #8
ericgsmith commentedThank you for the test Chris - much appreciate you picking that up. Test only job https://git.drupalcode.org/issue/drupal-3590537/-/jobs/9871035 is showing the failure
Comment #9
ericgsmith commentedComment #10
smustgrave commentedSmall comments but would be good to get exact steps to trigger this please.
Comment #11
xurizaemon@smustgrave I did my best to produce a "clean" steps to repro ... so far without success.
I see that the previous workaround #3565937: Workaround PHP bug with fibers and __get() (which this MR is a followup to) does not have steps to repro either, but we were able to agree on landing the fix there.
We have an 11.3 site where this patch reliably fixes the issue. We encounter the Fiber bug reliably both in local dev and hosted environments. The affected pages contain a number of embedded views which show Media documents (several tables, dozens of files but not hundreds); the pages use a number of contrib modules (eg DS + field templates, Advanced View Insert). Big Pipe is not enabled.
Eric and I should be able to debug & answer questions if that's helpful - we'd love to get this workaround fixed, as the PHP bug php/php-src#14983 underlying both #3565937: Workaround PHP bug with fibers and __get() and this issue is not resolved for any available PHP release to date.
Patch attached ("static" copy of the MR project/drupal!15791@1b6b9579), addresses the issue for our site(s) in the interim.
If I get the steps below working I will promote them to ID :)
Reproduction attempt
Configuration
composer require drupal/ds drupal/devel drupal/insert_view_adv drush/drushdrush site-install standarddrush -y en ds devel devel_generate insert_view_adv mediaadmin/config/content/formats/admin/structure/ds/settingsfile file-type-[media:field_media_document:entity:extension]href="[media:field_media_document]" type="[media:field_media_document:entity:mime]"{{ rendered_entity }}in another field to show the MediaContent setup
drush devel-generate:terms --bundles=tags 10drush devel-generate:media --bundles=document 100, etc
Execution
When the bug is in effect, we can trigger it by
drush crand a page reload; applying the patch and repeating will produce the page output.Comment #12
berdirThis is/was a known issue/major problem with the 11.3 on $entity->get('field')->entity, this is the same with isset(). I don't think this needs manual steps to reproduce, IMHO the scenario is clear and the fix is identical to __get().
I didn't review the changes in regards to the feedback or in general yet, so not setting to needs review/RTBC yet, but feel free to set back to needs review if you think the review was addressed. I am removing the tag.
Comment #13
smustgrave commentedWill leave for you all but not sure how to move an issue forward we don’t know why it triggers
Comment #14
xurizaemonThanks @berdir and @smustgrave, appreciated. Review welcome :)
Comment #15
smustgrave commentedNot sure how people are to review if they don’t know how to trigger this. Which manes it hard to tell if this is the right fix and therefore don’t know if the test coverage is correct. Just my thoughts
Comment #16
berdirI understand, but many of these fiber bugs we've seen in the last few months are very hard to reproduce by hand as you need very specific setup/data and it may also not be entirely stable in how it happens.
If you expand the scope in the MR up, you can see the exact same code in __get() (with the only difference being the parent call). FWIW, I think two cases isn't worth trying to generalize this, there shouldn't be third and it would make it even harder to read. As far as I'm concerned, that is sufficient in proving that this is the correct fix for now. We also hope to eventually remove this again, either in the open follow-up #3566626: [12.x] Use property hooks for EntityReferenceFieldItemList->entity or when php fixes this bug.
I haven't reviewed the tests yet, so not yet ready to RTBC, but I'll try to do that soon.