Problem/Motivation

We noticed some duplicates in one of our views.
It's a view that returns fields from relationships and uses grouping. The problem is that the view adds langcode columns to the GROUP BY even for fields that we don't want to add to the GROUP BY.

Steps to reproduce

I attached the YAML of a very simple view that reproduces the problem. It contains a relationship to an user and displays the user name.

If we set group_column: value on the user name field, it will generate this GROUP BY:

GROUP BY "users_field_data_node_field_data_name", "users_field_data_node_field_data_langcode"

This is fine and expected.

However, if we set group_column: entity_id, it generates this GROUP BY:

GROUP BY "users_field_data_node_field_data_langcode"

This is an unexpected behavior because I expected the users_field_data_node_field_data table to not be used in the GROUP BY at all.
I think it should only add the langcode column when another column of this table is added.

Proposed resolution

TranslationLanguageRenderer::query() should probably only be called when the corresponding EntityField is actually added to the query.

CommentFileSizeAuthor
views.view_.test.yml4.46 KBprudloff

Issue fork drupal-3362917

Command icon 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

prudloff created an issue. See original summary.

prudloff’s picture

Status: Active » Needs review
prudloff’s picture

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

Have not yet reviewed

But fix seemed to cause some failures.

Also will need it's own test case.

Should also try and aim for 11.x as that's the current development branch.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

prudloff changed the visibility of the branch 3362917-translationlanguagerenderer-adds-langcode to hidden.

prudloff’s picture

Status: Needs work » Closed (works as designed)

Calling $this->getEntityFieldRenderer()->query() seems necessary because it does not only add the GROUP BY, it also adds the langcode in SELECT so the entity can be rendered in the correct language.

And I can't reproduce the duplicate problem from the issue summary so I'm closing this.
I'll reopen if I manage to reproduce.

prudloff’s picture

I managed to reproduce my original duplicate problem and I think #2737619: Views entity reference relationships must join on langcode for translatable entities would be the correct way to fix this.