Sorting By Incorrect Column On Duplicate Column Names

Created on 28 September 2023, over 1 year ago

Problem/Motivation

When creating a view with one or more table relationships, it's possible that you have duplicate column names.
i.e. table1 > name
table2 > name

When you try to make both fields sortable, clicking on Name (table 2) column, actually sorts the table by Name (table 1).

The problem appears to be in:
/modules/contrib/views_aggregator/src/Plugin/views/style/Table::compareResultRows line 1410.

Steps to reproduce

1. Create a new view that against a table.
2. Add a relationship to a 2nd table that has a duplicate column name. i.e Table 1 > UserID, Table 2 > UserID.
3. Make both columns sortable in the Table Aggregator Settings.
4. View the report and sort on each of the columns.
5. They'll both sort based on the first column, never the 2nd.

Proposed resolution

I created a workaround by replacing on line 1410: $field_handler->options['entity_field'] with $this->active.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mitchmccoy

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mitchmccoy
  • πŸ‡ΊπŸ‡ΈUnited States mitchmccoy
  • Assigned to jordik
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    That piece of code was changed in #3059245: Rewrite main module functions to work with raw values β†’ by @JordiK, so I'm assigning the issue to him to look at because I don't know exactly what the intent was in that change.

    I don't think your workaround is the correct way to fix it though, because if the entity_id array element is not being accessed then we don't need to check to see if it's set anymore. But why was it being used in the first place? @JordiK should know ...

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    Upon re-reading my response in #3, I see it doesn't make sense, even to me. I think I must have posted that response in the wrong issue, because I talk about something that is not relevant to this problem. And specifically this piece of code was *not* altered or added by #3059245: Rewrite main module functions to work with raw values β†’ like I said.

    Sorry for the mistake.

    I think we need a test case to demonstrate the problem, which will also prove the proposed solution. That's going to be the hold-up in getting this fixed, but this module is not very maintainable without a good set of test cases and we don't have that yet. So when something like this is identified as a bug, it's extremely important to me that we write a test case to prove that the fixed code does things correctly.

  • πŸ‡¦πŸ‡ΉAustria jordik

    Good catch @mitchmccoy! Please check the patch.

  • πŸ‡¦πŸ‡ΉAustria jordik
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    We already have tests for sorting, in ViewsAggregatorStyleTableTest. This uses a test view with id va_test_style_table which is provided by the views_aggregator_test_config test module.

    I think we can add a test case for this issue with minimal effort, by modifying that test table so that it has the two columns/same name situation described in the OP. Then the already existing sorting tests should fail without the patch from #6?

Production build 0.71.5 2024