Views Term ID has broken filters ("All of", "Is none of") and contextual filters "allow multiple"

Created on 20 November 2016, over 7 years ago
Updated 9 May 2024, about 2 months ago

Problem/Motivation

  1. Create a vocabulary with some terms.
  2. Create a view of taxonomy terms
  3. New filter of Term
  4. Select "drop-down list"
  5. Choose "Is none of" or "Is all of" and select at least one term
  6. Apply

The loading spinner "spins" but not happens. And preview is not refreshed. The error return from the ajax handler is:

A valid cache entry key is required. Use getAll() to get all table data. in <em class="placeholder">Drupal\views\ViewsData-&gt;get()</em> (line <em class="placeholder">140</em> of <em class="placeholder">core/modules/views/src/ViewsData.php</em>). <pre class="backtrace">Drupal\views\Plugin\views\HandlerBase::getTableJoin(NULL, &#039;taxonomy_term_field_data&#039;) (Line: 88)
Drupal\views\ManyToOneHelper-&gt;addTable(Object) (Line: 243)
Drupal\views\ManyToOneHelper-&gt;ensureMyTable() (Line: 123)
Drupal\views\Plugin\views\filter\ManyToOne-&gt;ensureMyTable() (Line: 260)
Drupal\views\ManyToOneHelper-&gt;addFilter() (Line: 136)
Drupal\views\Plugin\views\filter\ManyToOne-&gt;opHelper() (Line: 389)
Drupal\views\Plugin\views\filter\InOperator-&gt;query() (Line: 1373)
Drupal\views\ViewExecutable-&gt;_build(&#039;filter&#039;) (Line: 1262)
Drupal\views\ViewExecutable-&gt;build(NULL) (Line: 1391)
Drupal\views\ViewExecutable-&gt;execute(NULL) (Line: 1454)
Drupal\views\ViewExecutable-&gt;render() (Line: 2454)
Drupal\views\Plugin\views\display\DisplayPluginBase-&gt;preview() (Line: 1662)
Drupal\views\ViewExecutable-&gt;preview(&#039;block_1&#039;, Array) (Line: 602)
Drupal\views_ui\ViewUI-&gt;renderPreview(&#039;block_1&#039;, Array) (Line: 62)
Drupal\views_ui\ViewPreviewForm-&gt;form(Array, Object) (Line: 106)
Drupal\Core\Entity\EntityForm-&gt;buildForm(Array, Object) (Line: 41)
Drupal\views_ui\ViewFormBase-&gt;buildForm(Array, Object, &#039;block_1&#039;)
call_user_func_array(Array, Array) (Line: 532)

Watchdog errors are:

Warning: Creating default object from empty value in Drupal\views\ManyToOneHelper->ensureMyTable() (line 232 of /app/drupal-91x/core/modules/views/src/ManyToOneHelper.php)

InvalidArgumentException: A valid cache entry key is required. Use getAll() to get all table data. in Drupal\views\ViewsData->get() (line 140 of /app/drupal-91x/core/modules/views/src/ViewsData.php).

Notice: Undefined property: stdClass::$leftTable in Drupal\views\ManyToOneHelper->addTable() (line 87 of /app/drupal-91x/core/modules/views/src/ManyToOneHelper.php)
πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 1 hour ago

Created by

πŸ‡«πŸ‡·France anou Collonges au Mont d'Or

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

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

    Also got this error recently just by removing a relationship in the UI. I have some other fields and filters that used it, and in Drupal 7 it'd fail successfully by removing the relationships where used. Core views should similarly be smarter and perform safe fallbacks instead of white-screen crashing the view with a bunch of throws.

  • πŸ‡¦πŸ‡ΊAustralia jude.hungerford

    I tried manually updating HandlerBase.php and ManyToOneAdapter.php in Drupal 9.5.9, based on this merge request:

    https://git.drupalcode.org/project/drupal/-/merge_requests/1624/diffs#no...

    I can confirm that Views with "Is none of" filters work after this patch. Without it, the View returns a white screen with the text "The website encountered an unexpected error. Please try again later".

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

    I am also getting this error on a large amount of views in our site. Basically any view that is filtering a taxonomy terms in a hierarchy or using none of. I haven't found a way past it yet. I'm on Drupal Core 9.5.10 right now but have downgraded all the way to 9.3 and this is still a problem.

  • πŸ‡¦πŸ‡ΊAustralia Ryanm81

    If it helps, to get the View back after breaking if you are getting the WSOD, you can just use the 'duplicate view' button to make a duplicate.

    Ofcourse you'll have to reassign the new view to existing blocks etc., but if you had some complex views you didn't want to start over from scratch like I did, this will help.

  • πŸ‡΅πŸ‡±Poland Patryk Padus

    There is another connection:
    - Add field (I use Commerce module)
    - Add new reference to this field in "View" -> "Advanced" -> "Reference"
    - Try to remove field, it won't remove it from View and won't list it as blocked by usage.
    - Get WSOD where view is used with referenced to non-exist field

    When re-adding issue gone and when removed issue back so this issue caused by UI and user so critical state is correct

  • πŸ‡¨πŸ‡¦Canada franceslui

    I am going to re-roll it to 10.1.x.

  • First commit to issue fork.
  • Merge request !5321Resolve #2829178 "Views term id 10 1" β†’ (Open) created by franceslui
  • Status changed to Needs review 7 months ago
  • πŸ‡¨πŸ‡¦Canada franceslui

    Reroll of merge request 1624 for Drupal 10.1.x. These were what I did:
    - changed the function name from 'testFilterGrouping' to 'testFilterGroupingWith2DifferentTerms' in my patch for the file TaxonomyIndexTidUiTest.php because the function testFilterGrouping exists in this php file in Drupal 10
    - added the statement 'use Drupal\views\Plugin\views\ViewsHandlerInterface;' in my patch for the file ManyToOneHelper.php
    - removed hunk #8 (the last hunk) from the original patch in merge request 1624 because the same code changes are already in Drupal 10

  • Status changed to Needs work 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Have not reviewed but seems to have a test failure

       PHPUnit Test failed to complete; Error: PHPUnit 9.6.8 by Sebastian Bergmann
        and contributors.
        
        Testing Drupal\Tests\user\Kernel\Views\HandlerFilterPermissionTest
        F                                                                   1 / 1
        (100%)
        
        Time: 00:02.142, Memory: 4.00 MB
        
        There was 1 failure:
        
        1)
        Drupal\Tests\user\Kernel\Views\HandlerFilterPermissionTest::testFilterPermission
        Failed asserting that actual size 0 matches expected size 3.
        
        /builds/issue/drupal-2829178/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122
        /builds/issue/drupal-2829178/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
        /builds/issue/drupal-2829178/core/modules/user/tests/src/Kernel/Views/HandlerFilterPermissionTest.php:65
        /builds/issue/drupal-2829178/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    
  • πŸ‡¦πŸ‡ΊAustralia jude.hungerford

    I've tested !5321 on Drupal 10.1.5, and I can confirm that the patch applies cleanly and it fixes our View with an "Is none of" filter.

  • πŸ‡³πŸ‡±Netherlands Lendude Amsterdam

    Lendude β†’ changed the visibility of the branch 10.1.x to hidden.

  • πŸ‡³πŸ‡±Netherlands Lendude Amsterdam
  • πŸ‡³πŸ‡±Netherlands Lendude Amsterdam

    Lendude β†’ changed the visibility of the branch 2829178-11.x to hidden.

  • πŸ‡³πŸ‡±Netherlands Lendude Amsterdam

    I tried to rebase some stuff into 11.x but no luck Β―\_(ツ)_/Β―

  • πŸ‡ΊπŸ‡ΈUnited States AaronBauman Philadelphia

    MR 5321 working for me on 10.1.7

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    I just ran into this. Not using a "drop-down list", but after adding a "Relationships: term" and "Contextual filters: (term) Taxonomy term: Name" I got:

    Error: Attempt to assign property "type" on null in Drupal\views\ManyToOneHelper->ensureMyTable() errors.

    The !5321 patch works well, and I can separate multiple terms with +, like this: view_page_path/abi+dam+cog and nodes tagged with those terms are shown.

    It does crash if I add a single term, with a lingering comma: view_page_path/abi,, or a lingering plus signview_page_path/abi+:

    TypeError: Cannot assign null to property Drupal\views\Plugin\views\argument\ArgumentPluginBase::$operator of type string in Drupal\views\Plugin\views\argument\ArgumentPluginBase->unpackArgumentValue() (line 1302 of core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php).

  • πŸ‡ΉπŸ‡­Thailand AlfTheCat

    5321 didn't work for me, in my case I tried to add an 'is one of' views filter of moderation states of a referenced node, using a relationship on the filter.

  • πŸ‡§πŸ‡ΎBelarus q2_faith

    Hi there,
    MR 5321 works for operator "Is one of" and doesn't work for "Is all of" but at least fixes error

    Error: Attempt to assign property "type" on null in Drupal\views\ManyToOneHelper->ensureMyTable() (line 220 of /var/www/html/web/core/modules/views/src/ManyToOneHelper.php).
    

    .
    I tried to figured out how to fix it but unsuccessfully. What I did(changes agains patch)

    1. Removed
      $join = $this->getTableJoin($join->table, $join->leftTable);
      

      in HandlerBase.php in 616 line. I think it isn't necessary to join table one more time because we already did it. Additionally, it doesn't work because the condition

      if (isset($data['table']['join'][$base_table])) {
      

      never returns true in method getTableJoin.

    2. The second place where we call method getTableJoin is in ManyToOneHelper.php line 112. On the behalf first point we get here null as well. I added checking on null.
      $r_join = HandlerBase::getTableJoin($r_join->leftTable, $base_table);
            if (!$r_join) {
              $r_join = clone $join;
              break;
            }
      

    Now query looks properly in Views preview but doesn't return any result. Like,
    INNER JOIN {taxonomy_term_field_data} "taxonomy_term_field_data_value_1" ON paragraphs_item_field_data_node__field_xxxx_xxxx__paragraph__field_xxxx_xxxx.field_xxxx_xxxx_target_id = taxonomy_term_field_data_value_1.tid AND taxonomy_term_field_data_value_1.tid = '68'
    And, I don't have idea how fix it. I will appreciate for any advice.
    Thanks!

  • πŸ‡©πŸ‡ͺGermany tobiasb Berlin

    For the "Is none of" use case I believe this part needs to be untouched. At least then it works again for list fields.

    @@ -275,8 +292,13 @@ public function addFilter() {
         // is set to TRUE, conditions will be added.
         $add_condition = TRUE;
         if ($operator == 'not') {
    -      $value = NULL;
    -      $operator = 'IS NULL';
    +      if (count($value) > 1) {
    +        $operator = 'NOT IN';
    +      }
    +      else {
    +        $value = is_array($value) ? array_pop($value) : $value;
    +        $operator = '!=';
    +      }
           $add_condition = FALSE;
         }
         elseif ($operator == 'or' && empty($options['reduce_duplicates'])) {
  • First commit to issue fork.
  • πŸ‡΅πŸ‡­Philippines dsdeiz

    Oh sorry, I didn't know it would automatically update the existing MR. I only added this change though - https://git.drupalcode.org/project/drupal/-/merge_requests/5321/diffs?co....

Production build 0.69.0 2024