Adding File Usage "File" relationship results in broken/missing handler

Created on 3 December 2015, over 8 years ago
Updated 29 February 2024, 4 months ago

Problem/Motivation

Relationship id is missing in "file_to_node", "node_to_file", "file_to_user", "user_to_file" and other file related relationships.

Steps to reproduce

-------- From original summary - ---------------
I am trying to add a relationship "file usage" to a view. I click the submit button, but the relationship never gets added and UI never closed. I can add other relationships as expected.

To replicate (with "standard" profile):

  1. Create a new view listing node content (no displays need to be added).
  2. Don't touch the base view config in any way (the default "title" field will be the only field, etc.)
  3. Add a File Usage "File" relationship via the UI

After these steps the relationship config dialog reports "The handler for this item is broken or missing" and no config form is displayed. The relationship can then be saved on the view (without configuration) but cannot be used.

Immediately upon adding the relationship an error similar to the following is printed in the views UI:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'fid' in 'field list': SELECT node_field_data.created AS node_field_data_created, node_field_data.nid AS nid, fid AS fid FROM {node_field_data} node_field_data WHERE (( (node_field_data.status = :db_condition_placeholder_0) )) ORDER BY node_field_data_created DESC LIMIT 10 OFFSET 0; Array ( [:db_condition_placeholder_0] => 1 )

And a barrage of notices are logged, containing and/or repeating:

Notice: Undefined index: id in Drupal\views\Plugin\ViewsHandlerManager->getHandler() (line 109 of /var/www/drupal-8/core/modules/views/src/Plugin/ViewsHandlerManager.php).
Notice: Undefined variable: items in Drupal\views\Plugin\views\relationship\Broken->buildOptionsForm() (line 79 of /var/www/drupal-8/core/modules/views/src/Plugin/views/BrokenHandlerTrait.php).
Notice: Undefined index: original_configuration in Drupal\views\Plugin\views\relationship\Broken->buildOptionsForm() (line 61 of /var/www/drupal-8/core/modules/views/src/Plugin/views/BrokenHandlerTrait.php).

Proposed resolution

- Add standard relationship id

Remaining tasks

Needs review

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

🐛 Bug report
Status

Fixed

Version

11.0 🔥

Component
File module 

Last updated 3 days ago

Created by

Live updates comments and jobs are added and updated live.
  • VDC

    Related to the Views in Drupal Core initiative.

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.

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue under control, following Review a patch or merge request as a guide.

    This ticket will need a test case to show the issue.

  • 🇯🇵Japan jorgemare

    Howdy,

    For what it's worth, after applying the patch in #99 to a Drupal 10.0.8 installation, the errors are gone and the (file) relationships work as expected in my views.

  • 🇺🇸United States crutch

    #99 or 53 fixes the issue for 9.5.9 when applied manually

  • 🇮🇳India mohit_aghera Rajkot

    Summarizing all the progress done so far.

    Patch in #99 fixes the issue.

    Patches from @Lendude #79 and #81 contains all the test cases.
    However those got removed during next re-rolls.
    One more attempt was done in comment #41, however #79 looks good enough to me.

    I've combined all the progress, and performed necessary tweaks in test cases and patch.

    I have included an interdiff, however it mostly contains all the test cases.
    Also, included test-only patch for reference. We already have a PR which is failing.

    Updated issue summary and hiding all other unnecessary patches.

  • Status changed to Needs review about 1 year ago
  • Open on Drupal.org →
    Environment: PHP 8.2 & MySQL 8
    last update about 1 year ago
    Waiting for branch to pass
  • Open on Drupal.org →
    Environment: PHP 8.2 & MySQL 8
    last update about 1 year ago
    Waiting for branch to pass
  • last update about 1 year ago
    29,404 pass, 1 fail
  • 🇮🇳India mohit_aghera Rajkot

    I think I put views config files in incorrect folder and that is causing issues.
    Fixing in the patch.

    Also, missed a couple of module dependencies in code formatting fixes.
    Adding those again. All the failing tests are passing on local now.

  • last update about 1 year ago
    29,406 pass
  • 🇮🇳India mohit_aghera Rajkot

    Removing depredations.

  • Status changed to RTBC about 1 year ago
  • 🇨🇦Canada nubeli

    I've reviewed and tested the patch in #112, which includes tests. Looks like it's all in order. I've applied the patch with composer locally and then did a drush cache rebuild. The error disappears.

    I'm not clear why this was switched to the 11.x-dev version back in #103. According to https://www.drupal.org/about/core/policies/core-release-cycles/schedule it seems that this bug fix could even go into 9.5.x. At the very least 10.0.x.

  • 🇺🇸United States smustgrave

    11.x is the current development branch. All code is committed there first and case by case backported to previous versions.

  • last update about 1 year ago
    29,411 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    30,377 pass
    • lauriii committed b8e76446 on 11.x
      Issue #2628230 by Lendude, mohit_aghera, wadmiraal, usrsbn, cilefen,...
    • lauriii committed 01f82e3f on 10.1.x
      Issue #2628230 by Lendude, mohit_aghera, wadmiraal, usrsbn, cilefen,...
  • 🇫🇮Finland lauriii Finland

    The fix looks right and was provided by one of the subsystem maintainers of Views 👍

    The test coverage looks good 👍 Made a minor adjustments on commit to the modules installed for the test.

    Committed b8e7644 and pushed to 11.x. Also cherry-picked to 10.1.x. Thanks!

    This may be qualified for a backport to 10.0.x and 9.5.x but checking with other committer.

  • Status changed to Needs work about 1 year ago
  • 🇳🇱Netherlands Spokje

    This commit has broken HEAD on 11.x and 10.1.x for pgsql only.

    TestBot merrily gives us the middle finger with:

    1) Drupal\Tests\file\Kernel\Views\RelationshipNodeFileDataTest::testViewsHandlerRelationshipFileToNode
    Drupal\Core\Database\DatabaseExceptionWrapper: Exception in test_file_to_node[test_file_to_node]: SQLSTATE[42883]: Undefined function: 7 ERROR:  operator does not exist: character varying = bigint
    LINE 5: ...ta" "node_field_data_file_usage" ON file_usage.id = node_fie...
                                                                 ^
    HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.: SELECT "file_managed"."fid" AS "fid", "node_field_data_file_usage"."nid" AS "node_field_data_file_usage_nid"
    FROM
    "test20724246file_managed" "file_managed"
    LEFT JOIN "test20724246file_usage" "file_usage" ON file_managed.fid = file_usage.fid
    INNER JOIN "test20724246node_field_data" "node_field_data_file_usage" ON file_usage.id = node_field_data_file_usage.nid AND file_usage.type = :views_join_condition_0
    LIMIT 11 OFFSET 0; Array
    (
        [:views_join_condition_0] => node
    )
    
    /var/www/html/core/modules/views/src/Plugin/views/query/Sql.php:1563
    /var/www/html/core/modules/views/src/ViewExecutable.php:1441
    /var/www/html/core/modules/views/tests/src/Kernel/ViewsKernelTestBase.php:127
    /var/www/html/core/modules/file/tests/src/Kernel/Views/RelationshipNodeFileDataTest.php:115
    /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    
    2) Drupal\Tests\file\Kernel\Views\RelationshipNodeFileDataTest::testViewsHandlerRelationshipNodeToFile
    Drupal\Core\Database\DatabaseExceptionWrapper: Exception in test_node_to_file[test_node_to_file]: SQLSTATE[42883]: Undefined function: 7 ERROR:  operator does not exist: bigint = character varying
    LINE 4: ...53file_usage" "file_usage" ON node_field_data.nid = file_usa...
                                                                 ^
    HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.: SELECT "node_field_data"."nid" AS "nid", "file_managed_file_usage"."fid" AS "file_managed_file_usage_fid"
    FROM
    "test13514853node_field_data" "node_field_data"
    LEFT JOIN "test13514853file_usage" "file_usage" ON node_field_data.nid = file_usage.id AND file_usage.type = :views_join_condition_0
    INNER JOIN "test13514853file_managed" "file_managed_file_usage" ON file_usage.fid = file_managed_file_usage.fid
    LIMIT 11 OFFSET 0; Array
    (
        [:views_join_condition_0] => node
    )
    
    /var/www/html/core/modules/views/src/Plugin/views/query/Sql.php:1563
    /var/www/html/core/modules/views/src/ViewExecutable.php:1441
    /var/www/html/core/modules/views/tests/src/Kernel/ViewsKernelTestBase.php:127
    /var/www/html/core/modules/file/tests/src/Kernel/Views/RelationshipNodeFileDataTest.php:177
    /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    

    See for example: https://www.drupal.org/pift-ci-job/2682293

    Unsure if we need to do the Rollbak-Rumba, or attempt a hotfix in here.

  • 🇫🇮Finland lauriii Finland

    It looks like the id column is a string whereas nid is an integer. Because of this, the patch only works with MySQL which is more relaxed about types. We need to decide whether we skip the tests for other database types than MySQL and fix this for other databases in a follow-up or revert this. The reason I think it might be fine to postpone fixing PostgreSQL to a follow-up is that the experience before and after this change is pretty much the same, it's just a different error that is being triggered now.

  • Status changed to Fixed about 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Pipeline finished with Skipped
    9 months ago
    #20207
  • Pipeline finished with Failed
    3 months ago
    Total: 293s
    #114202
  • Pipeline finished with Failed
    3 months ago
    Total: 269s
    #114218
  • Pipeline finished with Success
    3 months ago
    Total: 268s
    #114222
  • Pipeline finished with Failed
    3 months ago
    Total: 226s
    #114783
  • Pipeline finished with Failed
    3 months ago
    Total: 215s
    #115124
  • Pipeline finished with Failed
    3 months ago
    Total: 197s
    #118983
  • Pipeline finished with Success
    3 months ago
    Total: 308s
    #119527
  • Pipeline finished with Success
    3 months ago
    #119530
  • Pipeline finished with Failed
    3 months ago
    #124190
  • Pipeline finished with Failed
    3 months ago
    #124200
  • Pipeline finished with Canceled
    3 months ago
    #124209
  • Pipeline finished with Success
    3 months ago
    Total: 251s
    #124212
  • Pipeline finished with Canceled
    3 months ago
    Total: 67s
    #125086
  • Pipeline finished with Success
    3 months ago
    Total: 190s
    #125088
  • Pipeline finished with Canceled
    3 months ago
    Total: 82s
    #125092
  • Pipeline finished with Success
    3 months ago
    Total: 203s
    #125094
  • Pipeline finished with Failed
    3 months ago
    Total: 209s
    #127452
  • Pipeline finished with Success
    3 months ago
    Total: 180s
    #127455
  • Pipeline finished with Canceled
    3 months ago
    Total: 34s
    #129375
  • Pipeline finished with Failed
    3 months ago
    Total: 163s
    #129378
  • Pipeline finished with Success
    3 months ago
    Total: 380s
    #129401
  • Pipeline finished with Failed
    3 months ago
    #130120
  • Pipeline finished with Failed
    3 months ago
    #130124
  • Pipeline finished with Failed
    3 months ago
    #130127
  • Pipeline finished with Failed
    3 months ago
    Total: 314s
    #130132
  • Pipeline finished with Failed
    3 months ago
    Total: 228s
    #130138
  • Pipeline finished with Success
    3 months ago
    Total: 198s
    #130148
  • Pipeline finished with Success
    3 months ago
    Total: 200s
    #130152
  • Pipeline finished with Skipped
    2 months ago
    #136684
  • Pipeline finished with Failed
    2 months ago
    Total: 188s
    #143263
  • Pipeline finished with Success
    2 months ago
    Total: 222s
    #143280
  • Pipeline finished with Success
    2 months ago
    #144735
  • Pipeline finished with Success
    2 months ago
    #144758
  • Pipeline finished with Success
    2 months ago
    Total: 233s
    #144931
  • Pipeline finished with Canceled
    2 months ago
    Total: 362s
    #146726
  • Pipeline finished with Canceled
    2 months ago
    #146759
  • Pipeline finished with Failed
    2 months ago
    Total: 432s
    #146777
  • Pipeline finished with Failed
    2 months ago
    Total: 551s
    #146792
  • Pipeline finished with Success
    2 months ago
    Total: 185s
    #146825
  • Pipeline finished with Success
    2 months ago
    #146868
  • Pipeline finished with Success
    2 months ago
    Total: 184s
    #146874
  • Pipeline finished with Success
    2 months ago
    Total: 187s
    #146882
  • Pipeline finished with Canceled
    2 months ago
    Total: 128s
    #146898
  • Pipeline finished with Success
    2 months ago
    Total: 181s
    #146900
  • Pipeline finished with Failed
    2 months ago
    Total: 887s
    #147054
  • Pipeline finished with Canceled
    2 months ago
    Total: 456s
    #147886
  • Pipeline finished with Success
    2 months ago
    Total: 483s
    #147899
  • Pipeline finished with Success
    2 months ago
    Total: 609s
    #147916
  • Pipeline finished with Failed
    2 months ago
    Total: 196s
    #149297
  • Pipeline finished with Failed
    2 months ago
    Total: 223s
    #149308
  • Pipeline finished with Success
    2 months ago
    Total: 241s
    #149319
  • Pipeline finished with Failed
    about 2 months ago
    #151382
  • Pipeline finished with Success
    about 2 months ago
    Total: 163s
    #151395
  • Pipeline finished with Failed
    about 2 months ago
    Total: 210s
    #151439
  • Pipeline finished with Success
    about 2 months ago
    Total: 323s
    #151462
  • Pipeline finished with Success
    about 2 months ago
    Total: 190s
    #153304
  • Pipeline finished with Success
    about 2 months ago
    Total: 128s
    #158301
  • Pipeline finished with Success
    about 2 months ago
    Total: 130s
    #158304
  • Pipeline finished with Success
    about 2 months ago
    Total: 160s
    #158330
  • Pipeline finished with Success
    about 2 months ago
    #159950
  • Pipeline finished with Failed
    about 2 months ago
    Total: 122s
    #160739
  • Pipeline finished with Failed
    about 2 months ago
    Total: 208s
    #160804
  • Pipeline finished with Failed
    about 2 months ago
    Total: 297s
    #160822
  • Pipeline finished with Failed
    about 2 months ago
    Total: 280s
    #160887
  • Pipeline finished with Failed
    about 2 months ago
    Total: 214s
    #160938
  • Pipeline finished with Skipped
    about 1 month ago
    #162800
  • Pipeline finished with Failed
    about 1 month ago
    Total: 166s
    #163681
  • Pipeline finished with Failed
    about 1 month ago
    Total: 291s
    #163882
  • Pipeline finished with Failed
    about 1 month ago
    Total: 192s
    #163887
  • Pipeline finished with Failed
    about 1 month ago
    Total: 167s
    #163932
  • Pipeline finished with Canceled
    about 1 month ago
    Total: 7s
    #163938
  • Pipeline finished with Canceled
    about 1 month ago
    #163939
  • Pipeline finished with Canceled
    about 1 month ago
    #163941
  • Pipeline finished with Success
    about 1 month ago
    Total: 151s
    #163940
  • Pipeline finished with Success
    about 1 month ago
    Total: 266s
    #163942
  • Pipeline finished with Canceled
    about 1 month ago
    #163947
  • Pipeline finished with Failed
    about 1 month ago
    Total: 254s
    #163948
  • Pipeline finished with Success
    about 1 month ago
    #163950
  • Pipeline finished with Success
    about 1 month ago
    #164379
  • Pipeline finished with Success
    about 1 month ago
    Total: 168s
    #164644
  • Pipeline finished with Success
    about 1 month ago
    Total: 138s
    #164851
  • Pipeline finished with Success
    about 1 month ago
    Total: 348s
    #167837
  • Pipeline finished with Success
    about 1 month ago
    #167928
  • Pipeline finished with Success
    about 1 month ago
    #167945
  • Pipeline finished with Failed
    about 1 month ago
    Total: 173s
    #169949
  • Pipeline finished with Failed
    about 1 month ago
    Total: 171s
    #169959
  • Pipeline finished with Failed
    about 1 month ago
    Total: 204s
    #169970
  • Pipeline finished with Failed
    about 1 month ago
    Total: 169s
    #170053
  • Pipeline finished with Success
    about 1 month ago
    Total: 153s
    #170523
  • Pipeline finished with Success
    about 1 month ago
    Total: 161s
    #170525
  • Pipeline finished with Success
    about 1 month ago
    Total: 157s
    #170528
  • Pipeline finished with Failed
    29 days ago
    #175804
  • Pipeline finished with Success
    27 days ago
    #177271
  • Pipeline finished with Canceled
    25 days ago
    Total: 145s
    #179712
  • Pipeline finished with Skipped
    25 days ago
    #179715
  • Pipeline finished with Canceled
    21 days ago
    #182553
  • Pipeline finished with Success
    9 days ago
    Total: 262s
    #193440
  • Pipeline finished with Success
    6 days ago
    Total: 355s
    #195602
  • Pipeline finished with Success
    6 days ago
    Total: 260s
    #195668
Production build 0.69.0 2024