Problem/Motivation
Like the already committed #2913971: Views regression: 8.4.x EntityField can't handle a null row value from a non-required relationship, there are multiple places where the return value of \Drupal\views\Plugin\views\field\FieldPluginBase::getEntity is not checked for NULL values, leading to WSOD. Setting major thus.
Proposed resolution
Fix all these like in the linked issue. A muscling-through of the 25 occurences i could find is in attached patch.
Remaining tasks
Decide what tests we need and add them.
User interface changes
None.
API changes
Some internal methods' signatures changed from foo to foo|null. Given that the unexpected value null only occurs when until now we got a WSOD, this will not make anything worse for anyone.
* \Drupal\views\Entity\Render\EntityTranslationRenderTrait::getEntityTranslation
* \Drupal\views\Plugin\views\field\LinkBase::getUrlInfo
Data model changes
None.

| Comment | File | Size | Author |
|---|---|---|---|
| #207 | interdiff-3007424-205-207.txt | 1.71 KB | bhanu951 |
| #207 | 3007424-207-9.5.x.patch | 56.04 KB | bhanu951 |
| #205 | interdiff-3007424-164-205.txt | 25.63 KB | bhanu951 |
| #205 | 3007424-205-9.5.x.patch | 56.34 KB | bhanu951 |
| #201 | 3007424-201-10.0.x.patch | 56.2 KB | acbramley |
Issue fork drupal-3007424
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:
- 3007424-multiple-usages-of
changes, plain diff MR !3529
Comments
Comment #2
geek-merlinPatch flying in.
Comment #3
geek-merlinOK, #2 applies on 8.7 and 8.6, but 8.5 lacks media_library, so here's an 8.5 backport, please ignore.
Note: To patch a 8.5 instance, you also need (cleanly applying) patch from #2913971: Views regression: 8.4.x EntityField can't handle a null row value from a non-required relationship
Comment #4
joelpittetThis does fix an issue for me where a View gets an empty reference field from a node. Just hard to tell if the fixes are all related to this issue since they are fixed in a different way in some cases:
I'm not sure how this resolves to a WSOD
This also looks unrelated to the problem.
Comment #5
geek-merlinHmm, i remember that some changes to signatures to nonpublic methods had been necessary. And i remember that i was in a strong rush...
We should at least document those so NW.
Comment #6
yosia_ken commentedIn my condition, #2 & #3 still get TypeError:
TypeError: Argument 1 passed to Drupal\views\Plugin\views\field\RenderedEntity::getEntityTranslation() must implement interface Drupal\Core\Entity\EntityInterface, null given
I fix this with below:
Comment #7
aaronbaumanIn this patch:
re @joelpittet comments from #5,
1) hopefully this is clearer now that it's using if statements instead of the long ternary
2) the changes in LinkBase are necessary because of calls to checkUrlAccess() and getUrlInfo(). Hopefully the new patch is also clearer in this regard
Comment #8
aaronbaumanThis should have been updated in 2016 when this issue landed:
#2657826: FieldHandlerInterface::getEntity() can also return NULL
Not sure how this is currently evading all test coverage, nor the best way to add tests around this.
If someone wants to point me in the right direction, I can take a stab at writing some tests.
Generally, I don't think it's feasible to write tests for all the cases where callers may fail to type-check return values - that's pretty basic, could be caught e.g. by static analysis.
Comment #9
karenann commentedThe patch in #7 successfully addressed this particular issue in my environment.
In my instance, I have a view with a relationship based upon an entity reference; aka Content using field_name: Relate each Content with a field_name set to the content. I also have a "Content: Rendered entity" field using that relationship.
Pre-patch, in the cases where that relationship did not exist (the node was NOT referenced and had no relationship), I got the "TypeError: Argument 1 passed to Drupal\views\Plugin\views\field\RenderedEntity::getEntityTranslation() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in..." error.
Post-patch, no errors.
Comment #10
bmx269 commentedPatch #7 fixed my issues as well.
Comment #11
anruetherCan we set this to RTBC to get into 8.7? Deadline for core patches is March 8.
Comment #13
douggreen commentedSome of these changes already made it into 8.7. This issue needs another look and a preroll.
Comment #14
aaronbaumanComment #15
aaronbaumanThis is a straight re-roll of #7
@douggreen, i didn't see anything which had already been committed. Did you have something specific in mind?
Comment #16
daffie commentedThe patch looks good!
This can be rewritten to:
The default return value is NULL. Use this solution in multiple places for this patch.
Better is to test if $comment is an instanceof Drupal\Core\Entity\EntityInterface. Use this solution in multiple places for this patch.
Comment #17
aaronbaumanCan you expand on this feedback please?
Like I said previously, I don't see how it's feasible to write tests for all the cases where callers may fail to type-check return values.
Comment #18
daffie commented@AaronBauman: For each change/fix that your patch has, can you create a view which results into a WSOD and with your change/fix it does not. You can then write an automated test with your view and test that you do not get a WSOD. You create 2 patches, 1 with only the test and that one should fail. The second patch is the one with the test and the fix and that one should pass. I can help you with making the tests. Post for one change/fix the view with the problem and together we shall work out how to make that into an automated test. If you want to of course.
Comment #19
aaronbaumanHere are some tests that should fail.
Will post the patch which fixes them after testbot finishes.
These tests seem very overblown, given that the patch is a set of simple type checks.
Comment #21
aaronbaumanAnd here are the tests, along with fixes.
Omitting the interdiff, because #15 no longer applies so it's not particularly helpful.
Comment #23
brightboldPatch in #7 solved my problem on 8.7.5 (although in a couple of places the offset was too great and I had to patch those manually, if anyone else is patching 8.7) so thanks for the work on this; it will be great when this gets committed to 8.8.
Comment #24
dtv_rb commentedI stumbled over this error too a few minutes ago.
Somehow a node was not completely deleted. The row in the "node" table is gone, but the row in "node_field_data" is still there plus rows in some of the field tables and revision tables.
The /admin/content view created a WSOD.
I couldn't delete or edit or view this node via the Drupal interface.
I deleted the user (cancel user with deletion of all nodes), who owned the node. After that the admin/content view was ok again.
But the broken node was still not removed from the database.
What are the steps to remove all orphaned entries? Is it possible to just insert a row in the "node" table to make the node loadable/deletable again?
I don't want to manually delete rows in the database.
Comment #25
themic8 commentedI am having the same issue but only on the /admin/commerce/products view.
Still reviewing, but so far patch #15 is working well.
Project: Drupal Core 8.7.4 and Drupal Commerce 2.13.
Comment #26
nathan tsai commentedEncountered this problem today when I tried to render the latest comment of a node.
Since some nodes didn't have a comment, I got a the
TypeError: Argument 1 passed to Drupal\views\Plugin\views\field\RenderedEntity::getEntityTranslation() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in....The relevant part of patch #15 worked well for me:
Comment #27
jaykandariPatch #21 applies cleanly(8.7.x) and removes WSOD.
I had a problem with media overview page.
Still, need to find out how data got deleted in the main media table and data is present in media_field_data & other fields table. Possible due to script broke abnormally.
Comment #28
spokjeReroll of #21 for D8.7
Comment #29
spokjeSo the current tests in #19 and #21 all work with Mock views (
$view = $this->createMock(ViewExecutable::class))Those pass the tests for the actual issue here, but then fail later on because they're not "real" views with all their "real" properties.
Let's see if that's fixable by adding some "real test" views (if that makes even any sense to someone...)
Comment #30
spokje#21 with (trying to) addres #16.1
Comment #31
spokjeRight...let's pretend that never happened...
#21 with trying to addres #16.1
Comment #32
spokjeUploaded the same patch twice instead of patch + interdiff
Comment #33
spokjephpcs fixes and (hopefully) one less failure.
Comment #34
andypostbtw It does change return value of the actions - maybe instead of that just properly catch exceptions in calling code and document exceptions for actions?
Comment #35
YurkinPark commentedTests changed
Comment #36
spokje@YurkinPark Thank you!
- Fixed 2 Coding Standard Messages
- Removed changes in
core/modules/views/tests/src/Kernel/Handler/FieldEntityLinkTest.php. That only contained code formatting changes which I've inadvertently introduced in #33- Seperated the tests into a Test-Only.patch
If #34 needs to be addressed, at least we now should have a set of valid tests, I hope.
Otherwise: Review away! :)
Comment #38
jibranReroll after #2925816: Views plugin "Rendered Entity" must add langcode in render function
Comment #39
jibranRemoving the 'Needs tests' tag after #36.
Comment #42
jibranReroll for 8.7.x
Comment #43
tonytheferg commentedI also found this error when building a search result view for all content types:
TypeError: Argument 1 passed to Drupal\views\Plugin\views\field\RenderedEntity::getEntityTranslation() must implement interface Drupal\Core\Entity\EntityInterface, null given, called inThe view in question has a product relationship and a product variation relationship. The only field that threw the error in the view was the rendered entity for the add to cart form. This view also has product variation price field, as well as a taxonomy reference field from the product which haven't caused any noticeable issues.
The view would render fine when being filtered to only the content referencing products, but when any other content types without the product reference were trying to be rendered, I got the white screen. Hope this helps with troubleshooting.
Which patch is best to use right now for 8.7.8?
Thanks!
Comment #44
jibran#42
Comment #45
daffie commentedI took the patch from #38 and removed all the fixes. I want to check if the new tests will fail if the fixes are removed. Please do not give me commit credits for this creating this patch.
Comment #46
tonytheferg commentedJibran, isn't #42 failing tests right now? I'm new to this stuff.
Comment #47
daffie commented@ToneLoc: The 2 test failures are not related to the patch. So the testbot is green for the patch. You can do a review. See: https://www.drupal.org/patch/review.
Update: The failure is for by this patch added test : Drupal\Tests\media_library\Unit\MediaLibrarySelectFormTest. So back to needs work.
Comment #49
spokjeLet's see if this gets us closer to green
Comment #50
daffie commentedAdded #3058853: Drupal 8.x on Postgresql 12.
Comment #51
daffie commentedThe patch look good. Some (minor) points:
Could we, for better readability, rewrite this to:
and
Why are these files added? Wrong patch?!
Could we, for better readability, rewrite this to:
Should this test class not have a teardown method, because the container is being set?
Could we, for better readability, rewrite this to:
Could we, for better readability, rewrite this to:
Could we, for better readability, rewrite this to:
Could we, for better readability, rewrite this to:
Could we, for better readability, rewrite this to:
@Spokje: Thank you adding the tests.
Comment #52
tonytheferg commentedPatch from #28 fixed my issue from comment #43. Patch #48 would not install via composer, not sure if that is because of the 2 fails?
Comment #53
spokje@ToneLoc
Any error messages?
Comment #54
tonytheferg commentedI didn't copy it down, I think it was just the standard composer message could not apply patch...
Comment #55
mbovan commentedFew improvements to the patch.
I found examples in Core that explicitly return
NULLinstead of not returning anything in such cases. I updated the patch accordingly.Additionally, I updated the patch to assign a local
$entityvariable in one step instead of doing it in anifcondition. There are both examples in Core and I am not sure if there is an official convention for these cases. I think the changed way results in fewer lines changed.Also, addressed #51:
Comment #56
brightbold@ToneLoc The patch in #42 applied cleanly for me with composer on 8.7.9, so it's possible updating core might solve your problem.
Comment #57
mbovan commentedThis patch should fix test fails in
Drupal\Tests\media_library\Unit\MediaLibrarySelectFormTestappeared in #49 https://www.drupal.org/pift-ci-job/1467125.Comment #58
mbovan commented#57 patch rerolled on top of Drupal 8.7.9.
Comment #60
mbovan commentedThis fixes the test fail in
Drupal\Tests\views\Unit\Plugin\views\field\RenderedEntityTestI introduced in #55.At first, I reverted changes from #49 made in
Drupal\views\Plugin\views\field\RenderedEntity, but when I look into the documentation of::render()it says:That said, the return value should be an empty string if there is no entity.
Comment #63
daffie commentedIt all looks good to me. Just a couple of minor points left:
Can we combine the first lines to and remove the return null (returning null is the default action):
This line can be removed. It is the default action in php.
The same.
Comment #64
ravi.shankar commentedI have tried to make changes as suggested in #63. Please review it.
Comment #65
daffie commentedAlmost there:
The line
return '';should not have been removed.Comment #66
ravi.shankar commentedOh sorry I removed that also.
Comment #67
ravi.shankar commentedHere I have recreated patch, please review it.
Comment #68
ravi.shankar commentedI have recreated the patch.
Comment #69
daffie commented@ravi.shankar: You found my mistake from comment #63.1. If the patch is green I shall give it a RTBC.
Comment #70
daffie commentedThe patch looks good to me.
Tests have been added.
It is RTBC for me.
Great work everybody!
Comment #71
spokjeWow, I take my eyes off the ball for a few days and stuff got done.
Thanks @mbovan and @ravi.shankar for patching away and special thanks for @daffie for the excellent review work! 🙏
Comment #72
tonytheferg commentedCould not apply #68 with composer again for some reason. Patch from #28 is still applying cleanly via composer.
#68 neither with core 8.7.8 nor with 8.7.10. I did not try 8.7.9
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2019-11-13/3007424-64.patchMaybe it's a conflict with this other core patch I have: https://www.drupal.org/files/issues/2019-06-27/use-text-editor-for-summa...
Comment #73
tonytheferg commentedhaha. oops that's patch 64. :)
Comment #74
tonytheferg commentedSame for #68 tho.
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2019-11-14/3007424-68.patchComment #75
spokje@ToneLoc Patch #68 (and #64 as well) are tested against D8.9 and might work on D8.8.
As you've found out, they won't apply on D8.7.x.
Comment #76
tonytheferg commented@Spokje thanks. I didn't even know 8.9 was a thing yet. 😂
Comment #78
spokjeBack to RTBC as to #70
Testbot Failure was a random fluke as the next test I ran on the same patch was all green.
Comment #79
tormiConfirming that #58 applies on 8.7.11. Thanks, @mbovan!
Comment #80
rapindrive commented#68 this works correctly for me in 8.6.1 Thanks!!
Comment #81
embeau commented#68 works for me in 8.8.1. Thanks!
Comment #83
alternativo commented#68 ok for 8.8.5 php7.2 mySQL 5.6
Comment #85
acbramley commentedRerolled against 9.1.x-dev
Comment #87
aleevasTried to fix failure tests
Comment #89
aleevasNext try
Comment #91
acbramley commentedNice job @aleevas!
It looks like this was left over debugging?
Comment #92
narendra.rajwar27Comment #93
narendra.rajwar27Comment #94
narendra.rajwar27Patch applies for 9.1.x-dev in my local environment.
Comment #95
narendra.rajwar27Comment #96
acbramley commentedThanks @narendra.rajwar27, can you please provide an interdiff?
Comment #97
narendra.rajwar27sure @acbramley, interdiff for the patch in comment #94
Comment #98
narendra.rajwar27There is Patch issue in comment #94, as applied patch files were not neatly checked out in my local setup. which caused test cases removal, so updating again. Changes added as suggested in comment #91
Comment #100
narendra.rajwar27Comment #101
narendra.rajwar27Patch updated for failed test cases.
Comment #102
narendra.rajwar27Comment #103
daffie commentedPatch looks good.
Can we change this to: "$this->assertNull($field->render($row));". On multiple places.
You can remove the use-statement, when you change "Drupal::setContainer($container);" tot "\Drupal::setContainer($container);". On multiple places.
I think we need to do this in every unit test we are adding with setContainer() stuff. Missing it in the class MediaLibrarySelectFormTest.
Missing automated testing for this change. You can test a protected method by using reflection. On multiple places.
The variable $form is not necessary. On multiple places.
This line can be removed. There is already "@covers ::viewsForm". On multiple places.
Please change to "@covers ::render"
Please change to: "$view_entity = $this->getMockBuilder(View::class)". On multiple places.
We are adding NULL as a possible return value. Please add when that is the case. On multiple places.
Comment #104
aleevas@daffie thank you for the review.
About point 1:
I think, that the method
$this->assertEmptyis more fit for this case.I've fixed all notice from #104 except point 4.
Still needs to work on it
Comment #105
daffie commentedPatch looks better.
Should this not be:
$this->assertEmpty($field->options['id']);?Can we change the class definition to "ViewsPluginManager::class" and "DefaultDisplay::class".
The point #104.4 is still open.
Comment #106
mbovan commentedUpdates:
core/modules/media_library/tests/src/Unit/MediaLibrarySelectFormTest.phpandcore/modules/views/tests/src/Unit/Plugin/views/field/BulkFormTest.phptests.MediaLibrarySelectFormTestwas updated in #101 but I think we were not testing what we should.Comment #108
mbovan commentedFixed test fails in #106 in
MediaLibrarySelectFormTest.Comment #109
rsamsen commented@mbovan I've tried your patch on 8.9.1 but it's failing. Should it work on this version as well?
And more general: does this patch solve the error:
"TypeError: Argument 1 passed to Drupal\views\Plugin\views\field\EntityOperations::getEntityTranslation() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in /Applications/MAMP/htdocs/drupaluss/web/core/modules/views/src/Plugin/views/field/EntityOperations.php on line 142 in Drupal\views\Plugin\views\field\EntityOperations->getEntityTranslation() (line 69 of core/modules/views/src/Entity/Render/EntityTranslationRenderTrait.php). "
Edit: I found out I didn't apply the patch correctly. Big thanks to @Corn696 who (accidentally) gave an answer to my issue, about adding an extra section of your composer.json (https://www.drupal.org/project/social/issues/3093583)
Comment #110
smustgrave commentedTested with 9.0.5 and it seemed to strip all values out of the view. I'm seeing the rows but they're empty.
Comment #111
marcelovaniTested with 8.9.6 and it seems to work well
Comment #112
mrpauldriver commentedI was getting a WSOD when deleting Group posts. This appears to be resolved but like #110 I'm seeing blank rows in my content admin view.
Comment #114
b_sharpe commented@MrPaulDriver check this out: #3029355: Deleting a node deletes the linked group_content entities which then resaves the node
Comment #115
daffie commentedAll my points are addressed.
The patch is green for 9.2.
The patch looks good to me.
For me it is RTBC.
Comment #116
alexpottI'm not convinced that this patch is the correct direction. I'm not sure that soldiering on when expectations are not met is the correct behaviour.
I think this solution is incorrect. We're now breaking the interface of getUrlInfo() - this can't return NULL. It has to return a Url object.
I think here we need to trigger an exception - our expectations are not met. Also is it really true that getEntity() can return NULL for these plugins. I'm not convinced.
As above... this is moving the problem.
I think this change is not correct.
I think it is worth considering going the entirely opposite direction with the change.
i.e changing \Drupal\views\Plugin\views\field\FieldPluginBase::getEntity() to something like.
For me the big question is why/how are we calling these plugins when there is no entity. How do we get a row without an entity?
Comment #117
berdir> For me the big question is why/how are we calling these plugins when there is no entity. How do we get a row without an entity?
In my experience for one of three reasons:
a) Broken rows in the entity tables. There are some cases when a query can return a node ID but the node load for it is failing. For example if there is no default revision aka record in {node_revision}. I've seen this happen with migrate or so doing weird things. But we've added some safe guards for this a while ago. At least this is very hard to recover from when it does happen as you need to manually fix rows in your database.
b) Invalid cache invalidation, which shouldn't happen on its own but could result in the views data cache returning rows and then the load for that failing.
c) optional relationships that don't exist for a row. I might mix something up with another issue, but that should also be a possibility. So at least for that case, not being able to return an entity is an expected situation I think and not something we should. throw an exception for?
For a), maybe the sql query plugin could drop rows that fail to load an entity.
Comment #118
geek-merlin+1 for #117 c).
Note that this is just the aftermath of handling non-required relationships in #2913971: Views regression: 8.4.x EntityField can't handle a null row value from a non-required relationship.
Comment #119
alexpott#117.c is a good point. What then feels odd is that we try and render the value in this case at all. Surely if the relationship required by the plugin is optional and missing then we should short circuit all the processing an render an empty field... like a missing entity exception could help us do that. We could catch it in advancedRender()... but doing this would require extensive re-architecture and probably better test coverage of views than we have.
So the solution in #108 is probably the most pragmatic. Going to re-instate the rtbc from #115 and sleep on it.
Comment #120
marcelovaniAgree with #117, in my case it was caused by bad cache invalidation, I added steps to reproduce on this issue marked as duplicate
https://www.drupal.org/project/drupal/issues/3105003#comment-13849916
Comment #121
alexpottYeah but #120 is exactly what gives me pause. Your site has ended up in a situation it shouldn't have and this patch is masking the error. This patch will cause an incorrect version of the view to be cached because instead of triggering an error we've returned empty values and the view has been rendered. This can have serious consequences - imagine you have set up the view to add different information if the result is empty - for example - you have a list of limited stock items and if some column is empty you display that product is available. But the only reason it's empty is some cache error like in #120.
Comment #122
spokjeRe-uploading patch
3007424-108.patchso it gets re-tested every 2 days against9.2.x-dev.Currently is re-tested against
9.1.x-dev.Comment #123
catchAre we able to distinguish between #3007424-117: Multiple usages of FieldPluginBase::getEntity do not check for NULL, leading to WSOD (a)/(b) and (c), and if so log something in the case of (a)/(b)?
Comment #124
geek-merlin#123:
> [Should we] log something in the case of (a)/(b)?
Logging that should happen when "the node load for it is failing".
Logging that should be done when "the load for that failing".
So i'm inclined to say that's none of our business, and might or might not go to other issues.
"Our code" is just facing the situation of missing data, and can and should not care.
Comment #125
catchLogging when actually trying to load nodes would be a big change.
For example if I visit https://www.drupal.org/node/2 that's a 404. The only way Drupal knows it's a 404 is to try to load the node to see if it's there or not. Logging would potentially add a lot of noise.
If we don't log in entity load, then the next place up is the various callers, of which Views would be one.
Comment #126
berdirAgreed. Not every failed load is a problem. But in views, it very much is because the entities it loads are based on a query that it did just run and expects those ID's to exist. So it's views that needs to do the logging.
Comment #127
marcelovaniWhen I was testing this (see comment #120) I was running a behat test that deletes the generated users at the end, while I was constantly refreshing the admin/people page. The results were correct, but at some point it breaks.
I think the deletion of users is not correctly clearing the cache tags used by the view.
Comment #128
coderbrandon commentedI've added a complimentary issue and patch for Views Bulk Operations: https://www.drupal.org/project/views_bulk_operations/issues/3195468
Comment #129
mellowtothemax commentedPatch #108 worked for me on Drupal 8.9.13. Had the issue with /admin/commerce/products view. Not sure what caused it however as it was working fine until today. No changes were made to the site.
Comment #131
kim.pepperComment #132
tonytheferg commentedBeen using patch #108 for some time now, what is left before this can be RTBC?
Comment #133
spokjeBrowsing through this "Blast from the Past" it looks like @catch puts this back to NR to get more logging in #123 since this patch might probably only masking the root cause and was answered by @geek-merlin in #124 and finally @Berdir pointed out in #126 that this logging should take place in the views module.
So, in my tiny mind, this issue should be on
Needs Workfor that logging in views. If I misread anything, please correct me.Comment #134
danflanagan8Adding related issue in the #117(c) category: #2916597: TypeError when result row doesn't have an entity
Comment #140
larowlanComment #141
larowlanMarked #2916597: TypeError when result row doesn't have an entity as a duplicate
Comment #142
rcodinaI tried patch on #122 to solve...
... on admin/content and I've found a regression (see regression_patch_122.png). Content field values doesn't render.
Notice I landed in current issue via #3105003: TypeError: Argument 1 passed to Drupal\views\Plugin\views\field\EntityOperations::getEntityTranslation() must implement interface Drupal\Core\Entity\EntityInterface, null given,
Comment #146
acbramley commented#2939442: Views 'Entity Operations' field crashes if on a non-required relationship made similar changes to the EntityOperations field so this is a reroll for 9.5.x
Comment #147
socialnicheguru commentedConflicts with #2457999: Cannot use relationship for rendered entity on Views. Just posting to save others time as that has been committed to 10.1.
Comment #152
smustgrave commentedClosed #2715483: [regression] getEntity() doesn't always return entity, which results in add comment field not working in Views as a duplicate
Comment #153
akalam commentedI can confirm patch on #144 fixed the issue for me on Drupal 9.4.x
Comment #155
acbramley commentedRebased #146 onto an MR against 10.1.x. Setting to NR for core checks as they aren't running locally for me for some reason. Will try to address the last remaining piece of feedback (logging) after.
Comment #156
acbramley commentedSo in terms of logging, I'm not entirely sure where this is best placed. Putting it in
FieldPluginBase::getEntitywould make sense but it would have to be a very generic message since we don't have context of what the entity id or type is there.I think the only place we can really add it is where
_entityis set which looks like is inSql::assignEntitiesToResult. That would mean adding a new dependency on the logger service and that would mean we'd need a deprecation dance for any classes extending that plugin.Before I go down that route, it would be good to get confirmation from @catch and/or @Berdir that this sounds like the right approach.
Comment #157
larowlanFieldPluginBase::getEntity has the following available
$this->configuration['entity_type']for the entity-type$this->configuration['entity field']for the field name$values->indexfor the row index$this->view->id()for the view machine nameso in theory we could use that information to construct a reasonably informative log message
Comment #158
lendudeBack to NW for logging
Comment #159
acbramley commentedLogging added. Almost all tests needed updating to mock the logger factory so I've added a trait for that. Also removed the tearDowns which were unsetting the container as that happens in UnitTestCase::setUp anyway.
Almost certain there will be changes needed to the wording but this gets us into that convo :)
Comment #160
rohan-sinha commentedtested the MR !3529 , worked fell, all senerio covered, moving to RTBC done
Comment #161
larowlan@Lendude chance you could give this a +1 from a Views subsystem maintainer POV?
Comment #162
lendudeThe test look great, and as I see it we are handling all the needed cases. The only thing I don't really like is that how the NULLs are handled, it feels very inconsistent case-by-case. Sometime we have a guard statement with an early return, sometimes we have a big tertiary operator on the return statement, sometimes we just let the method run to the end and trust that to give a NULL and maybe some other variations.
My personal preference is just to have a guard statement as early as possible and return whatever we need in case of a NULL, but like I said, that is personal pref.
Not setting too 'Needs work' because this is not something that is inherently wrong, just personal opinion/feeling. The code does what it needs to do, so from that perspective it is RTBC.
Comment #163
larowlanAs this is a bug, can we also get a 9.5.x version? Thanks - it doesn't apply cleanly to 9.5.x.
Comment #164
acbramley commentedRolled for 9.5.x
Comment #165
smustgrave commentedMoving back to RTBC.
Compared patch #164 has all the changes in MR 3529 and they are all there except the change to phpstan-baseline.neon, (because it's not in 9.5)
Comment #166
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #167
smustgrave commentedMoving back to RTBC. Think the bot tried to apply the 9.5.x branch to 10.1.x
Comment #168
larowlanNew comments on the MR from @mstrelan
Comment #170
smustgrave commentedMoving to NW for additional comments in MR.
Comment #171
acbramley commentedI'll try and address this today
Comment #172
acbramley commentedAll comments addressed.
Comment #173
rohan-sinha commentedThe failing tests are related to the Drupal\FunctionalJavascriptTests\Tests\JSWebAssertTest class, specifically to the testJsWebAssert method. The error message suggests that there was a problem with the WebDriver, specifically with a stale element reference. This could be caused by the web page changing before the test could complete, or by an error in the test script itself.
Comment #174
rohan-sinha commentedTo correct this issue, the code for the JSWebAssertTest class needs to be reviewed and corrected. It is likely that the testJsWebAssert method needs to be updated to account for changes in the web page during testing. Additionally, the WebDriver configuration may need to be updated to ensure that it is properly interacting with the web page
Comment #175
dpiThese ChatGPT answers are not helpful.
How is it relevant to this issue? Restoring status.
Comment #176
smustgrave commentedThere still appear to be some open threads in the MR. Know you probably can't resolve them but could you leave a comment on them saying if they've been addressed or not needed.
Comment #177
acbramley commentedWeird, I thought I had applied all suggestions in the last push but I seem to have missed 5 of them...all applied now.
Comment #178
mstrelan commentedHave reviewed the MR and all feedback has been addressed with tests passing. API additions mentioned in the Issue Summary don't need a Change Record. This is good to go.
Comment #179
larowlanUpdating issue credits
Comment #181
larowlanCommitted to 10.1.x
Although there is a minor API change here (returning null instead of a Url) at present that code just blows up with a WSOD so I don't think this is disruptive (its a WSOD out of your hands now, it would be something you can do something about with this patch). So on that basis I think this is worth considering for 10.0.x and 9.5.x but I will get a second opinion.
Setting as patch to be ported in the meantime.
Comment #182
berdirThis is causing test fails in TMGMT :-/
I have a custom entity label field plugin there: \Drupal\tmgmt\Plugin\views\field\EntityLabel, this displays the label of an entity, and it's on an optional relationship (messages that might or might not have a reference to a job item).
Not only does this now log errors in a situation that is not unexpected, the logging also blindly asumes that there is an entity field in the configuration, which I think isn't necessary. It might be due to very old default views configuration but still, it shouldn't cause php warnings on this:
Warning: Undefined array key "entity field"
Drupal\views\Plugin\views\field\FieldPluginBase->getEntity()() (Line: 438)
I can work around it by checking if I have an ID, but http://grep.xnddx.ru/search?text=$this-%3EgetEntity($values) finds a bunch of similar use cases. I think what this should do is check for optional relationships and not log an error then.
Comment #184
larowlanReverted in light of #182 - let's see if we can make the logging conditional if the relationship is optional
Comment #185
acbramley commentedTaking a look
Comment #186
acbramley commentedWas a bit tricky to figure out how to reproduce the failure but I was able to by:
phpunit app/modules/contrib/tmgmt/translators/tmgmt_local/tests/src/Functional/LocalTranslatorTest.php --filter testBasicWorkflowWarning: Undefined array key "entity field" Drupal\views\Plugin\views\field\FieldPluginBase->getEntity()() (Line: 438)I then applied a fix (latest commit on the MR) and ran the tests again and they passed.
It seems like we don't have any tests in core that have an optional relationship with an entity that doesn't load, otherwise that would've triggered the same error? If anyone has pointers on where to put a test like that, that'd be great.
Comment #187
acbramley commentedTest pushed. It's pretty gross but does the job. Using a mock logger to save having to install dblog and query for logs.
Comment #188
berdirThe change looks good I think, didn't check the test. One part that's not covered yet is handling the case if there's no entity field configuration key, I think that's a valid situation.
Comment #189
acbramley commentedAdded a guard for #188
Comment #190
smustgrave commentedLast commit seems to cover #188.
Question is it possible on TMGMT to run tests with this as a patch? Not sure if that's possible in drupalci
Comment #191
larowlanLeft some questions on the MR
Comment #192
smustgrave commentedRemarking for committer review
The thread for this do we want to open a follow up?
Comment #193
larowlanThe thread in the MR has some suggestions now
Comment #194
acbramley commentedOk, hopefully this is the one 🤞
Comment #195
smustgrave commentedMarking this for @acbramley. Checked the threads have been resolved and recommended change for $this->label() ?: $this->realField was added.
Comment #196
socialnicheguru commentedThis applies and works.
I am placing this note here. It conflicts with #2457999: Cannot use relationship for rendered entity on Views on Drupal 9.5, which has been added to Drupal 10.1.
Comment #197
larowlanUnfortunately, this now needs a reroll, clash in phpstan-baseline.neon
Fine to self RTBC on resolution
Comment #198
acbramley commentedGreen after merge, back to RTBC
Comment #200
larowlanCommitted to 10.1.x, moving to 10.0.x for backport
Thanks all 🎉
Comment #201
acbramley commentedHere's a reroll for 10.0.x
Comment #202
smustgrave commentedReroll looks good.
Comment #204
larowlanCommitted to 10.0.x, moving to 9.5.x for reroll for that
Comment #205
bhanu951 commentedGot hit by this issue on a 9.5.x Project I am working on .
Back ported Latest 10.x patch to 9.5.x
Comment #206
smustgrave commentedSeems to have CI errors.
Comment #207
bhanu951 commentedFix CI Errors.
Comment #208
smustgrave commentedSeems like a good reroll.
Comment #209
larowlanAt this point, 9.5 is effectively security only.
There are a few commits in HEAD so there may be a bonus bugfix release, but we're not actively backporting any more issues at this point.
Thanks everyone.