Problem/Motivation

I've just updated from 2.0.2 to 2.1.0 and my views using aggregation now crash with:

> TypeError: Drupal\views_aggregator\Plugin\views\style\Table::setAggregatedGroupValues(): Argument #3 ($group_aggregation_results) must be of type int, string given, called in /var/www/html/web/modules/contrib/views_aggregator/src/Plugin/views/style/Table.php on line 40

I expect this is because the config type has been changed recently, or been made stricter.

The values in my config YAML files show a string for this value:

          group_aggregation:
            group_aggregation_results: '0'

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

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

joachim created an issue. See original summary.

joachim’s picture

I was thinking what would be needed here would be to do an update of existing config, but I've just tried creating a new view from scratch, and the preview crashes.

joachim’s picture

Ok, re-saving the view fixes the crash, so it *is* a config update that's needed.

The views preview crash is still happening, so that must be something else.

tr’s picture

Sounds like you didn't run update.php?

Yes, some config datatypes like the one you mention were corrected, but the update hook should have fixed that in any views that use this module. There's also a test that checks this update process to ensure they were corrected by the hook.

#3480009: Update Views options schema and turn on strict config schema checking in tests

tr’s picture

Status: Active » Postponed (maintainer needs more info)

@joachim: Did the update function work properly? I can't reproduce this problem, and as I said I believe the update function should be updating any views_aggregator table views on your site.

Are you still having the issue with the preview? If so I need steps to reproduce - if you are getting a crash with the preview I need the PHP error that you are seeing from your logs. I don't see that problem on my sites.

poker.ca’s picture

Same/similar issue here. After updating to 2.1.0, I ran update.php and cleared the caches, but still get this error when loading any page that uses this module. Other pages (tables) are working OK...
TypeError: Drupal\views_aggregator\Plugin\views\style\Table::getCellRaw(): Return value must be of type string, false returned in Drupal\views_aggregator\Plugin\views\style\Table->getCellRaw() (line 754 of /var/www/drupal/web/modules/contrib/views_aggregator/src/Plugin/views/style/Table.php).

poker.ca’s picture

Same/similar issue here. After updating to 2.1.0, I ran update.php and cleared the caches, but still get this error when loading any page that uses this module. Other pages (tables) are working OK...
TypeError: Drupal\views_aggregator\Plugin\views\style\Table::getCellRaw(): Return value must be of type string, false returned in Drupal\views_aggregator\Plugin\views\style\Table->getCellRaw() (line 754 of /var/www/drupal/web/modules/contrib/views_aggregator/src/Plugin/views/style/Table.php).

tr’s picture

@poker.ca: That's a different problem.
I opened up a new issue for your bug here: #3484017: Table::getCellRaw(): Return value must be of type string, false returned
Please read that issue,

joachim’s picture

> @joachim: Did the update function work properly? I can't reproduce this problem, and as I said I believe the update function should be updating any views_aggregator table views on your site.

I'm embarassed to report I hadn't run the update function. Running it fixes the crash -- the update function correctly changes the type of the group_aggregation_results property:

-            group_aggregation_results: '0'
+            group_aggregation_results: 0

However, the update function also made these changes which I'm confused about:

-            totals_per_page: 1
-            precision: 2
+            totals_per_page: 0
+            precision: 0
tr’s picture

-            totals_per_page: 1
-            precision: 2
+            totals_per_page: 0
+            precision: 0

In the previous version of the module, totals_per_page was sometimes a string and sometimes boolean. The update function sets it to 1 if the old value can be evaluated to true, and sets it to 0 otherwise. I don't see what went wrong here, because your old value was 1 and that should have evaluated to true, so the update function shouldn't have changed it.

For precision, the old type was a string, and the new type is integer. The update function just does a cast to an integer. So I don't see how that would have changed it from 2 to 0.

In both cases, it looks like your old values were already integers, which is puzzling because they were not declared or used as integers in the old version of this module. That was part of the point with this update - to fix the wrongly typed configuration variables. I have no explanation for why the values were wrongly changed - I tested this by installing an older version of the module, setting my totals_per_page and precision to your values, then running the update function, and it worked properly for me.

ericgsmith’s picture

Hi @tr

I have also experience this same result after updating (the unexpected config diff of '1' => 0 and '2' => 0, not the original issue summary)

It looks like there is a missing . in views_aggregator_update_10200 between the key and property for when the current values of precision and totals_per_page are fetched which is then not getting the actual values and setting them as 0.

E.g. the value comes from $key . 'column_aggregation.precision' and is set to $key . '.column_aggregation.precision'

ericgsmith’s picture

Status: Postponed (maintainer needs more info) » Needs review

Opened MR for that - https://git.drupalcode.org/project/views_aggregator/-/merge_requests/29/...

EDIT

I see now that this is not really to do with the original summary only the last few comments in this issue #3485998: Totals per page and column precision always set to 0 in views_aggregator_update_10200 so I moved it to a new issue - wasn't sure if it was better to reword / take over this issue or open a new one

ericgsmith’s picture

Status: Needs review » Postponed (maintainer needs more info)
tr’s picture

Priority: Critical » Normal

It is my understanding that the original issue described in the issue summary was because update.php had not been run.

The additional problem with totals_per_page and precision that was raised by @joachim in #9 is a bug and was correctly diagnosed by @ericgsmith in #11. That bug is now fixed, and there is a new release 2.1.1 now so that no-one else will have that same issue. See #3485998: Totals per page and column precision always set to 0 in views_aggregator_update_10200 for further details.

I think this issue can be closed now?

clava’s picture

After an update to 2.1.1 I still get an error:
TypeError: Drupal\views_aggregator\Plugin\views\style\Table::getCellRaw(): Return value must be of type string, false returned in Drupal\views_aggregator\Plugin\views\style\Table->getCellRaw() (line 754 of modules/contrib/views_aggregator/src/Plugin/views/style/Table.php).

tr’s picture

@clava: As I already said in response to #6/#7, that's a different issue. I gave a link to that issue, and that is where that problem is being worked on. It has nothing to do with this issue.

tr’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

As per #16. The original issue was because update.php wasn't run - it wasn't a bug in this module.
The subsequent problem raised in #9 was fixed in a different issue.
Nothing left to fix here.

mortona2k’s picture

I'm getting this error on a fresh install on Drupal 11.

All I did was create a view, and enable this display. I'm unable to get past the error with any settings.

davidwhthomas’s picture

Status: Closed (works as designed) » Active
StatusFileSize
new250.22 KB

The original error in this post still occurs in 2.1x, so I'm reopening this issue. For example, when updating the table settings in the View with auto-preview enabled, you can see the error.

It appears to happen because the values for the views option form "group_aggregation_results" element are set to integers (0,1), while the HTML form input value will return a string ("0", or "1") ref: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement

i.e

    $form['group_aggregation']['group_aggregation_results'] = [
      '#title' => $this->t('Aggregation results per group'),
      '#type' => 'radios',
      '#options' => [
        0 => $this->t('results will be aggregated with one row per group'),
        1 => $this->t('no aggregation, results will be shown after each group (like subtotals)'),
      ],
      '#description' => $this->t('Select the second option, if you want to show subtotals'),
      '#default_value' => $this->options['group_aggregation']['group_aggregation_results'],
      '#weight' => -2,
    ];

The module config schema is set to use an integer for that field too, but views will sometimes return a string for the form input value, because HTML. While it's probably better to just use a string for that value, assuming it needs to be an integer, another solution would be to allow a string or integer to be passed to Drupal\views_aggregator\Plugin\views\style\Table::setAggregatedGroupValues for the $group_aggregation_results parameter.

davidwhthomas’s picture

Status: Active » Needs review
mortona2k’s picture

This got it working for me, thanks!

I can't really account the parameter type question, but it looks like this change should be compatible with what's currently there.

nwells’s picture

I can confirm the same issue on a new Drupal 11 install

I updated Drupal\views_aggregator\Plugin\views\style\Table::setAggregatedGroupValues to allow for int|string as suggested in #21 and that resolved the issue for me.

ifrik’s picture

I have the same issue when updating 2.0.2 to 2.0.3

davidwhthomas’s picture

Status: Needs review » Reviewed & tested by the community
roxflame’s picture

On my install (dev version) it still wasn't working after patching with #21, I updated the following around line 861 to cast the string to int if present

          $custom_delimiters = str_getcsv($matches[1][0], ',', "'");
          // Use int for decimal places
          $custom_delimiters[0] = (int) $custom_delimiters[0];
          // Check if arguments are set, otherwise use dot for default decimal.
davidwhthomas’s picture

@roxflame although #28 may have a similar cause, it appears to be a different issue from the title and topic addressed in this issue.

skaught’s picture

+1 more.

branch: views_aggregator-data-type-fix-3482129-2
-> https://git.drupalcode.org/project/views_aggregator/-/merge_requests/36....
patch allows by view to work as expected.

flameingo’s picture

+1

When I save the modal, the value of the variable $group_aggregation_results is a string, which causes an error message. If you then save the view, you don't get this error because the value is then of type integer. Patch from #30 solves the problem.

Drupal Version: 11.2.8

TypeError: Drupal\views_aggregator\Plugin\views\style\Table::setAggregatedGroupValues(): Argument #3 ($group_aggregation_results) must be of type int, string given, called in /HOME/web/modules/contrib/views_aggregator/src/Plugin/views/style/Table.php on line 406 in Drupal\views_aggregator\Plugin\views\style\Table->setAggregatedGroupValues() (line 1161 of /HOME/web/modules/contrib/views_aggregator/src/Plugin/views/style/Table.php).

olivierh65’s picture

Same problem, and patch solves it.

kyle.carter changed the visibility of the branch views_aggregator-data-type-fix-3482129-2 to hidden.

kyle.carter changed the visibility of the branch views_aggregator-data-type-fix-3482129-2 to active.