Problem/Motivation
Let's assume the following scenario:
- Create a node
- Create a forward revision for this node
- Create a module which tracks the latest (not the default revision) and integrate it with views: (#2702041: Add views relationship from content to latest revision)
- Execute the view
Expected result
It works as expected
Actual result
Fatal in \Drupal\views\Plugin\views\query\Sql::getCacheTags due to a method call on NULL.
Proposed resolution
The problem
\Drupal\views\Plugin\views\query\Sql::loadEntities treats revision IDs and entity IDs partially the same, see $flat_ids = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($ids)), FALSE);. The current loading of revisions though works, because, a) Either we start with the revision base table, which let's us load all the revisions anyway or b) We start with the node table and join on the default revision, so we load the default entity always.
You can reproduce this with the attached view.
Note: Therefore you need a node with default revision ID = 4, but one revision with revision ID 5.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | interdiff.txt | 1.59 KB | dawehner |
| #26 | 2714989-26.patch | 35.86 KB | dawehner |
| #24 | interdiff.txt | 2.68 KB | dawehner |
| #24 | 2714989-24.patch | 35.86 KB | dawehner |
| #19 | 2714989-19.patch | 35.89 KB | dawehner |
Comments
Comment #2
dawehnerComment #3
dawehnerComment #4
dawehnerThis is a prototype of a patch.
Comment #5
dawehnerThis time with a test
Comment #8
dawehnerAnd a small bugfix
Comment #10
dawehnerThere are some things, I simply don't understand.
Comment #11
jibranFixed the fail patch as well.
Comment #13
jibranSome minor feedback other that this is RTBC.
We can be little optimistic in comment.
Technically @see should be at the end of the doc block.
Comment #14
dawehnerThank you for the review!
Well, I just moved things around ...
Comment #15
traviscarden commentedI tested the patch in #14, and it worked for me and fixed #2714717: Content (nid) relationship joins to wrong nodes. I'm probably not deep enough into this to RTBC it, though.
Comment #16
jibranThanks @dawehner for fixing feedback.
Comment #17
alexpottMissing doc block.
I guess we can backport this to 8.1.x by adding an _ to
assignEntitiesToResult()if we want.Reviewing the code here is painful.
Comment #18
dawehner@alexpott and myself agreed on adding unit tests for this quite complex piece of code.
Comment #19
dawehnerAdded some unit test coverage as well as documentation.
Comment #20
jibranSeems perfect now.
Comment #21
alexpottCommitted e888be3 and pushed to 8.2.x. Thanks!
@dawehner nice coverage. Using the _ method we can port this fix to 8.1.x
Unused use removed on commit.
Comment #23
jibranSeems like a novice task.
Comment #24
dawehnerI'm sorry, I just did that
Comment #26
dawehnerThere we go
Comment #28
dawehnerIts green again ...
Comment #29
kristiaanvandeneyndeIt's green and it prefixes a new protected method with an underscore as mentioned in #2744157: [policy, no patch] Clarify the policy around backporting changes with potential issues. It changes nothing aside from that, so looks like a clean backport to me.
Comment #30
alexpottCommitted c6ed7c9 and pushed to 8.1.x. Thanks!
Comment #33
Chris Gillis commentedI was having the same symptoms with a custom view in Drupal 8.3.7. I went through all the relations and marked them "required". This fixed the issue. Just noting this here for findability.
Comment #34
amaisano commentedHaving this problem on 8.4.0. The view is using the content_revisions base table and has a relationship to both the moderation_state as well as the main node. Requiring the relationships did not resolve the issue as in the previous comment.
When deleting a revision, returning to this revisions view afterwards triggered the error.
I completely disabled caching on that display and the issue went away.
Comment #35
phillipHG commentedHaving the same issue on 8.4.0. I tried disabling caching (caching: none in advanced view settings) as mentioned in #34, but still issue happens.