Ajax error on views with aggregation.

Created on 28 February 2023, over 2 years ago

Problem/Motivation

ajax.js?v=9.5.3:448 Uncaught
Drupal.AjaxError
message
:
"\nAn AJAX HTTP error occurred.\nHTTP Result Code: 200\nDebugging information follows.\nPath: /web/admin/structure/views/ajax/handler-group/latest_activity/block_1/field/field_last_update_en\nStatusText: OK\nResponseText: TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 687 of /var/www/html/web/core/modules/views/src/Plugin/views/field/EntityField.php)."
name
:

Steps to reproduce

Enable aggregation on a view , add a date field, set the aggregation to some value, try to resave.

🐛 Bug report
Status

Active

Version

9.5

Component
Views 

Last updated about 13 hours ago

Created by

🇧🇬Bulgaria ovidenov

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

Merge Requests

Comments & Activities

  • Issue created by @ovidenov
  • Status changed to Postponed: needs info over 2 years ago
  • 🇳🇿New Zealand quietone

    I happen to be testing with Views right now and saw this issue. I tried to reproduce this on Drupal 10.1.x, umami install and, so far, have not been able to.

    Can you elaborate on what you did to "set the aggregation to some value"? Thanks.

  • 🇳🇱Netherlands Rop Rotterdam

    I get a simular error:

    TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (regel 687 van /var/www/[site]/web/core/modules/views/src/Plugin/views/field/EntityField.php)

    I can save the view though. The error occurs when trying to change the aggregation function on one of my fields from COUNT to anything else. The modal won't close.

    Drupal: 9.5.8
    Php:8.1.18

    I guess the provided patch #2 is not really a solution, since the provided value SHOULD be an array, so the question is why is it NULL instead? The problem is something other, so If we just skip handling it when it is not an array we are only hiding an error, not fixing it.

  • 🇺🇸United States mkindred

    I ran across this issue today. I was trying to create a simple admin report showing the number of images (media) attached to each node of a particular content type. (I need to limit the number of images that my client adds to an existing 'product' content type, but first we need a report showing how many he's currently using per product.)

    Here are the steps I took (in D9.5.10):

    1. Create a view for a single content type, table list of fields.
    2. Add a relationship to each of two media fields (images in my case).
    3. Add two image fields to the view, each using one of the two relationships above.
    4. Turn on aggregation. The aggregation works as expected, except that the two fields' counts are multiplied by each other.
    5. I tried to change the aggregation type for the two image fields from 'Count' to 'Count DISTINCT'. But the modal won't close, and I'm seeing an error in watchdog:

    TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 687 of /var/www/html/drupal/web/core/modules/views/src/Plugin/views/field/EntityField.php)

    As mentioned in #4, I'm not sure patch #2 is the correct solution, but it prevents the error, allows me to save the aggregation settings per field, and gives me the view I want.

  • Status changed to Needs work almost 2 years ago
  • 🇳🇱Netherlands Lendude Amsterdam

    Closed 🐛 Aggregation in views causes ajax error Closed: duplicate as a duplicate, very similar patch there.

    Thanks for the steps to reproduce, we will need an automated test for this too.

  • 🇵🇱Poland besek

    I had the same issues, with very similar steps to reproduce as described in #5 🐛 Ajax error on views with aggregation. Active .
    Patch from #2 🐛 Ajax error on views with aggregation. Active wroked well for me.

  • 🇮🇹Italy turneight

    I report the patch proposed in the discussion closed because it was duplicated

  • last update almost 2 years ago
    30,142 pass, 2 fail
  • last update almost 2 years ago
    29,477 pass
  • last update almost 2 years ago
    29,477 pass
  • last update almost 2 years ago
    30,377 pass
  • 🇫🇷France xavier.masson Haute-Normandie

    Thanks for the patch, the patch from #8 🐛 Ajax error on views with aggregation. Active works as expected on Drupal core 9.5.11 !

  • last update over 1 year ago
    30,667 pass
  • last update over 1 year ago
    30,667 pass
  • 🇺🇸United States crutch

    Patch doesn't apply to 10.1.8

    When manually changing /core/modules/views/src/Plugin/views/field/EntityField.php and not changing /core/modules/views_ui/src/Form/Ajax/ConfigHandlerGroup.php then the error is gone and works normally again.

  • 🇫🇷France dqd London | N.Y.C | Paris | Hamburg | Berlin

    @#8 this hasn' addressed #6 yet. This issue needs a reroll of #2 or #8 with the points made in #6.

  • last update over 1 year ago
    25,805 pass, 1,851 fail
  • 🇮🇹Italy turneight

    #8 on drupal 10.2 and php 8.3 is still working for me.
    #2 hides the problem but does not solve it, the aggregation configuration remains blocked.
    I'm sorry but I am currently unable to develop the tests.

  • 🇫🇷France dqd London | N.Y.C | Paris | Hamburg | Berlin

    @Turneight: Thanks for coming back on this! +1

  • Status changed to Postponed: needs info over 1 year ago
  • 🇳🇱Netherlands Lendude Amsterdam

    Rereading this, feels like a duplicate of 🐛 Switching on aggregation generates fatal "Column not found: 1054 Unknown column" SQL error when using multi-column Fields Needs work can somebody check if the work there helps fix their issues?

  • 🇺🇸United States crutch

    For me, this issue was happening having a view with (1) Integer (2) Embed containing a single integer field which is aggregated and a (3) Simple Math Field to achieve a result. I simply could not modify aggregation at (2) at some point and found this issue. #14 speaks to multi-column fields which I wasn't using a display field with multi-columns, but in the (2) Embed field, there is a date filter which is related to this original issue. Aggregation is applied to filters and the display integer field at (2). I assume date is a multi-column field like image.

  • 🇦🇺Australia 2pha

    #8 seems to work for me

  • i have the same issue using D10.2.3, with default theme. I get this error if i try to aggregate decimal or text fields.

    Here's the error I'm getting in javascript console:

    [Error] Failed to load resource: the server responded with a status of 500 () (ref_pollutant_category, line 0)
    [Error] AjaxError:
    An AJAX HTTP error occurred.
    HTTP Result Code: 500
    Debugging information follows.
    Path: /admin/structure/views/ajax/handler-group/recommended_ef_charts/block_2/field/ref_pollutant_category
    StatusText: error
    ResponseText: The website encountered an unexpected error. Try again later.TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 692 of core/modules/views/src/Plugin/views/field/EntityField.php). Drupal\views\Plugin\views\field\EntityField->submitGroupByForm(Array, Object) (Line: 106)
    Drupal\views_ui\Form\Ajax\ConfigHandlerGroup->submitForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 264)
    Drupal\views_ui\ViewUI->standardSubmit(Array, Object)
    call_user_func_array(Array, Array) (Line: 129)
    Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 67)
    Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
    Drupal\Core\Form\FormBuilder->processForm('views_ui_config_item_group_form', Array, Object) (Line: 325)
    Drupal\Core\Form\FormBuilder->buildForm('Drupal\views_ui\Form\Ajax\ConfigHandlerGroup', Object) (Line: 215)
    Drupal\views_ui\Form\Ajax\ViewsFormBase->Drupal\views_ui\Form\Ajax\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 217)
    Drupal\views_ui\Form\Ajax\ViewsFormBase->ajaxFormWrapper('Drupal\views_ui\Form\Ajax\ConfigHandlerGroup', Object) (Line: 127)
    Drupal\views_ui\Form\Ajax\ViewsFormBase->getForm(Object, 'block_2', 'ajax') (Line: 38)
    Drupal\views_ui\Form\Ajax\ConfigHandlerGroup->getForm(Object, 'block_2', 'ajax', 'field', 'ref_pollutant_category')
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    and here's the error in the recent log:

    Location: https://wfrd.ddev.site/admin/structure/views/ajax/handler-group/recommen...
    Message: TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 692 of /var/www/html/web/core/modules/views/src/Plugin/views/field/EntityField.php).
    Backtrace:
    #0 /var/www/html/web/core/modules/views/src/Plugin/views/field/EntityField.php(692): array_filter(NULL)
    #1 /var/www/html/web/core/modules/views_ui/src/Form/Ajax/ConfigHandlerGroup.php(106): Drupal\views\Plugin\views\field\EntityField->submitGroupByForm(Array, Object(Drupal\Core\Form\FormState))
    #2 [internal function]: Drupal\views_ui\Form\Ajax\ConfigHandlerGroup->submitForm(Array, Object(Drupal\Core\Form\FormState))
    #3 /var/www/html/web/core/modules/views_ui/src/ViewUI.php(264): call_user_func_array(Array, Array)
    #4 [internal function]: Drupal\views_ui\ViewUI->standardSubmit(Array, Object(Drupal\Core\Form\FormState))
    #5 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(129): call_user_func_array(Array, Array)
    #6 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(67): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
    #7 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(597): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
    #8 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm('views_ui_config...', Array, Object(Drupal\Core\Form\FormState))
    #9 /var/www/html/web/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php(215): Drupal\Core\Form\FormBuilder->buildForm('Drupal\\views_ui...', Object(Drupal\Core\Form\FormState))
    #10 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\views_ui\Form\Ajax\ViewsFormBase->Drupal\views_ui\Form\Ajax\{closure}()
    #11 /var/www/html/web/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php(217): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #12 /var/www/html/web/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php(127): Drupal\views_ui\Form\Ajax\ViewsFormBase->ajaxFormWrapper('Drupal\\views_ui...', Object(Drupal\Core\Form\FormState))
    #13 /var/www/html/web/core/modules/views_ui/src/Form/Ajax/ConfigHandlerGroup.php(38): Drupal\views_ui\Form\Ajax\ViewsFormBase->getForm(Object(Drupal\views_ui\ViewUI), 'block_2', 'ajax')
    #14 [internal function]: Drupal\views_ui\Form\Ajax\ConfigHandlerGroup->getForm(Object(Drupal\views_ui\ViewUI), 'block_2', 'ajax', 'field', 'ref_pollutant_c...')
    #15 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    #16 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #17 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #18 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
    #19 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #20 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #21 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #22 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #23 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #24 /var/www/html/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #25 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #26 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #27 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #28 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #29 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #30 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #31 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #32 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #33 {main}

  • Status changed to Needs work over 1 year ago
  • 🇳🇿New Zealand john pitcairn

    Re #14 and #15: This is not specific to multi-column fields. I can reproduce it with a single entityreference field in a view of commerce subscriptions.

    I can set aggregation for the field to COUNT, and apply.

    But thereafter I cannot remove or change the aggregation for the field. Clicking apply will produce the ajax error.

    Un-postponing.

  • 🇫🇷France GuillaumeDuveau Toulouse

    #8 seems to work for me too.

  • 🇫🇷France yonailo Paris

    Yes #8 works for me too (I am running Drupal 10.3.0)

  • 🇮🇳India Binoli Lalani Gujarat

    binoli lalani made their first commit to this issue’s fork.

  • 🇮🇳India Binoli Lalani Gujarat

    binoli lalani changed the visibility of the branch 3344910-ajax-error-on to hidden.

  • 🇮🇳India Binoli Lalani Gujarat

    binoli lalani changed the visibility of the branch 3344910-ajax-error-on to active.

  • Pipeline finished with Failed
    9 months ago
    Total: 582s
    #338302
  • 🇮🇳India Binoli Lalani Gujarat

    Hello,

    I created MR as part of new process of contribution.

    Please review.

    Thanks!

  • 🇺🇸United States smustgrave

    Previously tagged for test which still appear to be needed.

    Issue summary also appears to be incomplete.

  • 🇹🇭Thailand AlfTheCat

    The latest MR fixed the issue on my end: I could not set the aggration settings to "Count Distinct" which was breaking aggregation in my view all together. After the patch, it all worked.

    Thanks everyone for the great work on this so far.

  • 🇺🇸United States loze Los Angeles

    This MR works. I'm constantly running into this issue with aggregated views. Thanks!

  • Patch #8 working for me, Drupal 10.4.7.
    Thanks!

  • 🇮🇳India joshua1234511 Goa

    I attempted to add a test, but reproducing the AJAX behavior and accurately triggering the failure in a test scenario is significantly more complex than the actual fix itself. Given that the MR directly resolves the issue.

    Tested the merge Request - Resolves the issue.

    I would suggest proceeding with merging the fix as is, and leaving a follow-up issue open specifically for adding test coverage.

  • ### Manual review

    **Reproduced**
    * Clean Drupal **11.2.x** install.
    * Enabled *Aggregation* in **Views → Advanced → Other**.
    * Added a **Date** field with an aggregation function.
    * Saving the View triggered the Ajax error reported.

    **Patch tested**
    Applied **#2** — `3344910-2-views-aggregation-error.patch` (MR !11081).

    **Result**
    * View now saves/updates without Ajax errors.
    * Aggregated results render correctly.
    * No new PHP warnings/notices observed.

    **Environment**
    Drupal 11.2 • PHP 8.3 • MySQL 8.0 • Local stack (DDEV + Docker)

    ---

    ✅ The patch fixes the issue for me.

  • 🇧🇪Belgium BramDriesen Belgium 🇧🇪

    Re #31, what did you actually test? You're referencing the patch from #2, but also the MR  !11081 which contains more changes as the patch...

  • 🇺🇸United States smustgrave

    We don’t really merge in fixes and push test coverage unless it’s critical which this does not count, sorry

  • RE #32 Sorry for the mix‑up.I was juggling several tickets and accidentally copied the wrong reference. I’ve tested patch #2 on a fresh Drupal 11.2 setup (PHP 8.3) and it fixes the Ajax error which i was able to replecate on my drupal 11 setup by following the above mention steps . All tests were done manually. I’m still new to this and will double‑check ticket numbers from now on.Thank u for highlighting my mistake from now on i will keep this on my mind

Production build 0.71.5 2024