TypeError: Drupal\views_aggregator\Plugin\views\style\Table::setCell(): Argument #2 ($row_num) must be of type int, null given

Created on 20 December 2024, 4 months ago

When rendering a aggregated view, some times this error occurs

TypeError: Drupal\views_aggregator\Plugin\views\style\Table::setCell(): Argument #2 ($row_num) must be of type int, null given, called in /var/www/site/releases/32/web/modules/contrib/views_aggregator/src/Plugin/views/style/Table.php on line 1191 in Drupal\views_aggregator\Plugin\views\style\Table->setCell() (line 780 of /var/www/site/releases/32/web/modules/contrib/views_aggregator/src/Plugin/views/style/Table.php).

In the views_aggregator/src/Plugin/views/style/Table.php line 1191, the setCell function is called with NULL as second parameter, and the definition of the function typecasts the parameter as INT, and therefore an exception is thrown.

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡©πŸ‡°Denmark ramlev

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

Merge Requests

Comments & Activities

  • Issue created by @ramlev
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    Yes, the code appears to be wrong - adding the type case simply revealed the error. Can you post an export of a simple view that demonstrates the problem?

  • niharika.s β†’ made their first commit to this issue’s fork.

  • Merge request !32Updated mr β†’ (Open) created by Unnamed author
  • I have applied the changes according to the issue in Table.php file please review it.

  • Pipeline finished with Success
    4 months ago
    Total: 239s
    #377794
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    No, that doesn't fix the problem, it just avoids an error message.
    We already have

        if (isset($row_num)) {
        }
        else {
       }

    And $row_num is allowed to be NULL. So if it needs to be used in the else clause, that's where the change should be made. Setting $row_num to 0 is a huge assumption.

    But more importantly, we have to first identify why this is a problem. Is it only when the table has no content so there are no rows? That's why I asked for an export of a simple view that demonstrates this problem. That way we can have a test that shows the problem, proves that the fix works, and prevents the problem from happening again in the future.

  • πŸ‡ΊπŸ‡ΈUnited States shamilto2000

    I was also having this error, but I was able to fix it by changing a setting in my view.

    The format of the view is Table with Aggregation Options. Previously under Group aggregation options, I had checked "no aggregation, results will be shown after each group (like subtotals)." I have changed this to "results will be aggregated with one row per group."

    This is not ideal, as I would like to see the subtotals. Perhaps this can help you locate the source of the problem.

  • πŸ‡¬πŸ‡§United Kingdom Krys15

    I also had this error.

    I was applying 2 aggregations the first to 'group and compress', the second 'maximum'. I removed the maximum aggregation, and my page is working again. I suspect the second aggregation is not performing any useful function, but I've not yet tested fully.

  • πŸ‡©πŸ‡°Denmark ramlev

    The patch does not resolve the issue.

    The problem arises because the $row_num parameter in the setCell method is typecast as an integer. However, in several instances within the code, it is called with a NULL value. Additionally, the methods renderNewValue and renderNewWebformValue both accept $row_num as a parameter, but one method typecasts it while the other does not.
    I believe the solution is to either remove the typecasting altogether, or it appears that the issue can be resolved by modifying the setCell() method as follows:

    From:

    public function setCell(FieldHandlerInterface $field_handler, int$row_num, $new_values, string $separator) {

    To:

    public function setCell(FieldHandlerInterface $field_handler, int|null $row_num, $new_values, string $separator) {

  • πŸ‡©πŸ‡°Denmark ramlev

    Attached a patch that solves the issue

  • πŸ‡©πŸ‡ͺGermany butch.coolidge Reutlingen

    We were having the same error, Patch #10 works.
    Thanks very much.

Production build 0.71.5 2024