Problem/Motivation
0. Create a site with two languages and some translated content.
1. Create a view of revisions.
2. Look at the "langcode" part of the select query.
3. Observe it is selected with "langcode as langcode" instead of "node_field_revision.langcode AS node_field_revision_langcode"
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #40 | views-entity_row_renderer_revision-2896381-30-tests-only.patch | 9.53 KB | catch |
| #30 | views-entity_row_renderer_revision-2896381-30.patch | 12.41 KB | plach |
Comments
Comment #2
sam152 commentedI don't expect this is the correct fix, but it illustrates the problem area of the code.
Basically from what I can grok, the return value of $query->ensureTable() is NULL when using the revision as the view base table. Hence the following situation comes up:
The docblock defines $table as:
So the field is assumed to be a formula and is selected as:
langcode as langcodeinstead of:
node_field_revision.langcode AS node_field_revision_langcodeThe langcode always comes from the basetable of the view, so somehow, we should use that instead?
Comment #3
sam152 commentedComment #4
sam152 commentedComment #5
sam152 commentedComment #6
tacituseu commentedComment #7
sam152 commentedClosing this in favour of #2446681: Error "Column 'langcode' in field list is ambiguous" thrown due to TranslationLanguageRenderer not rendering a field from a relationship.
Thanks for the tip off.
Comment #8
plachNot actually a duplicate, see #2446681-26: Error "Column 'langcode' in field list is ambiguous" thrown due to TranslationLanguageRenderer not rendering a field from a relationship.
Comment #9
plachHere's an attempt to fix this properly.
Comment #10
plachComment #11
plachComment #12
sam152 commentedThis patch reads correctly to me based on what I was observing. If the view base table is the entity revision table, use that instead of the return value of $storage->getTableMapping()->getFieldTableName() which is the base table.
+1 RTBC
Comment #13
timmillwoodTook me a while to understand what's going on, and still not 100% sure, but this seems to make sense.
Comment #14
berdirThat's a creative way of using a switch :)
This should at least have a comment that explains this I think.
One confusing thing is that we are mixing terminoly here. an "entity base table" is never the revision or revision data table. But this isn't the entity base table, it's the views base table, so maybe we should use $views_base_table to make that distinction a bit clearer?
Comment #15
timmillwood@Berdir - this is the part of the patch that took me longest to understand, so yes, commenting and updating variable names is a good suggestion.
Comment #16
plachGood points :)
Comment #17
plachAddressed the review above.
Comment #18
plachForgot the comment, sorry.
Comment #20
timmillwoodLovely!
Comment #21
amateescu commentedI'm glad to see this was so easy to fix. I just found a couple of points to address:
By looking at the method definition, it seems that the
$relationshipparam is not really optional?We should break out of this habit of returning FALSE when we actually can (and should) return NULL :)
Comment #22
plachActually the method will always return a string.
Comment #23
amateescu commentedGreat, that reads much better now ;)
Comment #24
jibranComment #25
jibranTranslationLanguageRendererchanges look good to me.This comment convinced me.
Just one questions: This is just adding the correct table to the query. It wouldn't affect the existing view in the storage. It would affect only their output. Right?
Comment #26
plachYes, it's just ensuring the query is generated correctly at runtime.
Comment #27
jibranThanks, RTBC +1
Comment #28
timmillwoodThis is blocking #2862041: Provide useful Views filters for Content Moderation State fields so hopefully we can get it committed for better Views support in Content Moderation.
Comment #29
tacituseu commented@plach: curious about the
!$relationshippart of:is this meant to limit the scope ? (there are two other issues affected by the same part of code and showing similar symptoms),
would you see an advantage of doing it like this instead:
to cover both cases.
Comment #30
plach@tacituseu:
Well, actually, the reason is there is no way to define a revision relationship AFAIK. But that's a good suggestion, if it is introduced then the code should work automatically.
Comment #31
plachComment #32
tacituseu commented@plach: Indeed, I'm so used to running with the ERR patch adding it that I totally forgot about it, thanks.
Edit: Manually tested #30 with the ERR patch and it works just fine.
Comment #33
plachCool, can you point me to the issue?
Comment #34
tacituseu commentedIt's #2799479: Views doesn't recognize relationship to host, I referenced this one from it already.
Comment #35
plach@tacituseu:
Thanks, any other concern or can we move this back to RTBC?
Comment #36
tacituseu commentedNone from me, setting back.
Comment #38
timmillwoodThis is required by #2862041: Provide useful Views filters for Content Moderation State fields which is required for Content Moderation to become stable, so moving back to 8.4.x
Comment #39
tacituseu commentedSince this blocks a Major should-have it should be Major too.
Comment #40
catchWhy is this necessary when $query is typehinted?
Everything else looks good, the inline comments in the patch are useful.
Uploading a test-only patch for the bot since I can't see one on the issue. The
Comment #42
catchGood fail.
Comment #43
amateescu commentedRe #40.1: That's because the method type hints the generic
QueryPluginBaseclass and we're using some methods that are only in\Drupal\views\Plugin\views\query\Sql, so basically for better IDE autocompletion :)Comment #44
catchOK, those aren't my favourite comments, but fair enough.
Committed/pushed to 8.5.x and cherry-picked to 8.4.x. Thanks!