Problem/Motivation
EntityViewsData adds the entity type to all tables that it exposes.
\Drupal\views\Plugin\views\query\QueryPluginBase::getEntityTableInfo() loops over all relationships and if it finds entity type, it assumes it is an entity base table and attempts to add the id/revision id field to it.
For those additional fields, that fails badly.
Proposed resolution
Check if the table actually has the field that we want to add, just skip it if not.
As an alternative, don't add the entity type, but according to @dawehner, that's not correct either.
Remaining tasks
Fix getEntityTableInfo()Fix broken testsAdd new test coverage- Decide new test coverage is adequate and relevant
User interface changes
NA
API changes
NA
Data model changes
Views query is more selective when adding entities from relationships.
Comment | File | Size | Author |
---|---|---|---|
#34 | drupal_2729325_8.1.x_35.patch | 4.08 KB | Xano |
#33 | interdiff.txt | 617 bytes | Xano |
#14 | interdiff.txt | 1.07 KB | yanniboi |
Comments
Comment #2
BerdirComment #3
dawehnerIts IMHO certainly better than not adding the flag to the multivalue base fields, but we should think about all the places where we use it maybe first.
Comment #5
yanniboi CreditAttribution: yanniboi at FreelyGive commentedI've spotted a bug in TermViewsData. We changed the base table for node to node_field_data and that was breaking the test.
Comment #7
jibranWe need tests for this.
Comment #8
yanniboi CreditAttribution: yanniboi at FreelyGive commentedComment #9
yanniboi CreditAttribution: yanniboi at FreelyGive commented@jibran, I spoke to @alexpott yesterday, and that change is quite difficult to test. Also there is an issue to replace the term index relationship with a generic entity relationship, so as long as we have test coverage for the change in @berdir's patch that should be enough.
Comment #10
yanniboi CreditAttribution: yanniboi at FreelyGive commentedAdded test to cover changes to getEntityTableInfo().
Comment #11
yanniboi CreditAttribution: yanniboi at FreelyGive commentedMoving to 8.2.x
Comment #12
YesCT CreditAttribution: YesCT commentedI talked to @yanniboi in person asking these questions (and included some of his nice answers here.)
so this was already wrong, but we didn't know cause we weren't using the name of the base field to check things. And this new test does. So this fix was needed. See #5 interdiff (fixing previous patch fails)
these added id's and vid's are needed now, cause without the fix to core, they were not being skipped (which is what this test wanted) but with the fix, they were being skipped. So explicitly set them so they are not skipped and this test works as intended. See #8 interdiff (fixing previous patch fails)
this test is copy and pasted from other similar tests. unknown if we want to repeat that here, or ... add a comment to the similar tests so they are related.
nit (double blank line)
these asserts seem to be the key. And it makes sense to test before that first is there, so that entity_first_field_data__entity_first_field_data not being there actually is meaningful. (if first wasn't there, then testing if the base field was not there wouldn't mean much)
So I guess the only real question about this... is if we want so much of the duplicated test here, that might not be strictly relevant to this particular test condition.
I kinda feel like the test could use some more comments about what the set up is... but it might also be that others wont need comments (and if the code is copy and pasted form another test, than commenting might be out of scope).
Comment #13
yanniboi CreditAttribution: yanniboi at FreelyGive commentedUpdated issue summary
Comment #14
yanniboi CreditAttribution: yanniboi at FreelyGive commentedRemoved @YesCT's nitpick and added some comments to the test.
Comment #15
YesCT CreditAttribution: YesCT commentedThanks!
uh, I thought first was a table, and entity_first_field_data__entity_first_field_data was a base field?
Also, why is this bug major? https://www.drupal.org/core/issue-priority#major-bug
Comment #16
YesCT CreditAttribution: YesCT commentedThis is the reason I'm asking about wording.
Comment #17
yanniboi CreditAttribution: yanniboi at FreelyGive commentedThis bug is major because it basically breaks any view with a relationship to an non entity table.
So according to @dawehner, we don't just want to exclude entity base tables, we want to exclude:
So while our current fix sort of works it feels a bit *hacky*.
Maybe we can think of a better way of doing this?
Comment #19
YesCT CreditAttribution: YesCT commentedComment #20
BerdirI don't understand why or what the problem is.
We're looking for the presence of the ID or revision ID. All of the 4 tables you listed have those
Comment #21
dawehnerWell, we are talking about potentially arbitrary tables, which just happen to have the same columns. Just imagine maybe an entity type that has a 'entity_id' as 'id' key.
Comment #22
BerdirHere's the approach we discussed, explicitly checking the entity base tables. Looks like the changes to SqlTest are no longer necessary then. Also removed a few unit test changes that are no longer necessary.
I still like my idea of not adding this information to those tables, will see about uploading a patch for that tomorrow.
Comment #23
dawehnerThanks a ton @berdir!
Its good to see whether alternative approaches also work.
Can we create its own issue for this change? The most recent approach should still support it. ... The problem here is that we probably need an update path for it.
IMHO this approach is one with the least possible BC problems.
Comment #24
BerdirRemoved that part.
Comment #25
BerdirTried my idea. You were right, of course. the entity type key is used, in \Drupal\views\ViewExecutable::addHandler() for example. Don't fully understand why it didn't work as I expected and maybe it could be worked around, but you're right, this is most BC approach.
Comment #26
dawehnerJust some quick nitpick ...
Let's use
$this->assertContains
and$this->assertNotContains
Comment #27
yanniboi CreditAttribution: yanniboi at FreelyGive commentedNitpick addressed.
Comment #28
XanoI tested @yanniboi's patch from #27 on Payment, of which the view on
/admin/content/payment
is broken because of this problem. I can confirm the patch fixes the problem. To reproduce:/admin/content/payment
./admin/content/payment
again.I will leave the RTBC to someone else, because I do not know if this solution is the best possible one for this issue.
Comment #29
dawehnerThank you @yanniboi
In general I'm quite convinced of this solution. It provides the minimal chance of a BC break.
Comment #30
XanoSee #28 for the reason this is a blocker.
Comment #31
XanoHere is the patch from #27 for 8.1.x.
Comment #33
XanoThis should fix the last remaining test failure on 8.1.x.
Comment #34
Xano#33's interdiff is correct, but its patch does not contain the changes.
Comment #36
XanoOh hello, weekend!
Comment #37
Xano#27 contains the latest patch for 8.2.x.
#33 contains the latest patch for 8.1.x.
I am RTBC'ing this per #29, because all I did was fix an erroneous code comment, as proven by the tests passing.
Comment #38
alexpottGiven what @dawehner says in #29 only going to commit the 8.2.x - I don't want to take any chance of BC break in 8.1.x.
Committed c7cc44e and pushed to 8.2.x. Thanks!
Comment #40
BerdirHm, I'm not sure that's what @dawehner meant with that comment :). We are not aware of any BC break and I can't imagine what could break it.
Note that for example payment.module is broken without this fix, so it would be a bit unfortunate if we have to wait for 8.2 to come out. And this is a regression in 8.1, caused by #2644088: DefaultTableMapping::getFieldTableName does not report table for fields with dedicated storage, it works in 8.0 because the field tables never have this key. And I have this patch applied in NP8 and never had a problem with it so far.
Just want to make sure you have all the information when making the 8.1 decision here, feel free to set it back to fixed if you want to keep it that way. I personally can live with maintaining my patch a while longer.
Comment #41
dawehnerRight, the solution we went with is the one which has no known BC break yet, unless some of the earlier ones. If you join to the base table, adding the entity IDs should be safe.
Comment #42
alexpottCommitted 126d2a1 and pushed to 8.1.x. Thanks!