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.

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

ramlev created an issue. See original summary.

tr’s picture

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.

niharika.s’s picture

Status: Active » Needs review

I have applied the changes according to the issue in Table.php file please review it.

tr’s picture

Status: Needs review » Postponed (maintainer needs more info)
Issue tags: +Needs tests

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.

shamilto2000’s picture

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.

krys15’s picture

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.

ramlev’s picture

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) {

ramlev’s picture

Attached a patch that solves the issue

butch.coolidge’s picture

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