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

Created on 3 December 2015, about 9 years ago
Updated 29 February 2024, 10 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 1 day 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 almost 2 years 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 ilfelice

    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 over 1 year ago
  • Open on Drupal.org →
    Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    Waiting for branch to pass
  • Open on Drupal.org →
    Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    Waiting for branch to pass
  • last update over 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 over 1 year ago
    29,406 pass
  • 🇮🇳India mohit_aghera Rajkot

    Removing depredations.

  • Status changed to RTBC over 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 over 1 year ago
    29,411 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.0 & MySQL 5.7
    last update over 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 over 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 over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Pipeline finished with Skipped
    over 1 year ago
    #20207
  • Pipeline finished with Failed
    10 months ago
    Total: 293s
    #114202
  • Pipeline finished with Failed
    10 months ago
    Total: 269s
    #114218
  • Pipeline finished with Success
    10 months ago
    Total: 268s
    #114222
  • Pipeline finished with Failed
    9 months ago
    Total: 215s
    #115124
  • Pipeline finished with Success
    9 months ago
    Total: 308s
    #119527
  • Pipeline finished with Success
    9 months ago
    #119530
  • Pipeline finished with Success
    9 months ago
    Total: 251s
    #124212
  • Pipeline finished with Canceled
    9 months ago
    Total: 67s
    #125086
  • Pipeline finished with Canceled
    9 months ago
    Total: 82s
    #125092
  • Pipeline finished with Failed
    9 months ago
    Total: 209s
    #127452
  • Pipeline finished with Failed
    9 months ago
    Total: 163s
    #129378
  • Pipeline finished with Success
    9 months ago
    Total: 380s
    #129401
  • Pipeline finished with Failed
    9 months ago
    #130124
  • Pipeline finished with Failed
    9 months ago
    Total: 314s
    #130132
  • Pipeline finished with Failed
    9 months ago
    Total: 228s
    #130138
  • Pipeline finished with Success
    9 months ago
    Total: 198s
    #130148
  • Pipeline finished with Success
    9 months ago
    Total: 200s
    #130152
  • Pipeline finished with Skipped
    9 months ago
    #136684
  • Pipeline finished with Success
    8 months ago
    #144758
  • Pipeline finished with Success
    8 months ago
    Total: 233s
    #144931
  • Pipeline finished with Canceled
    8 months ago
    Total: 362s
    #146726
  • Pipeline finished with Canceled
    8 months ago
    #146759
  • Pipeline finished with Success
    8 months ago
    Total: 184s
    #146874
  • Pipeline finished with Success
    8 months ago
    Total: 187s
    #146882
  • Pipeline finished with Canceled
    8 months ago
    Total: 128s
    #146898
  • Pipeline finished with Success
    8 months ago
    Total: 181s
    #146900
  • Pipeline finished with Failed
    8 months ago
    Total: 887s
    #147054
  • Pipeline finished with Canceled
    8 months ago
    Total: 456s
    #147886
  • Pipeline finished with Success
    8 months ago
    Total: 609s
    #147916
  • Pipeline finished with Failed
    8 months ago
    Total: 223s
    #149308
  • Pipeline finished with Failed
    8 months ago
    #151382
  • Pipeline finished with Success
    8 months ago
    Total: 163s
    #151395
  • Pipeline finished with Success
    8 months ago
    Total: 190s
    #153304
  • Pipeline finished with Success
    8 months ago
    Total: 128s
    #158301
  • Pipeline finished with Success
    8 months ago
    Total: 160s
    #158330
  • Pipeline finished with Success
    8 months ago
    #159950
  • Pipeline finished with Failed
    8 months ago
    Total: 122s
    #160739
  • Pipeline finished with Failed
    8 months ago
    Total: 208s
    #160804
  • Pipeline finished with Failed
    8 months ago
    Total: 297s
    #160822
  • Pipeline finished with Failed
    8 months ago
    Total: 214s
    #160938
  • Pipeline finished with Failed
    8 months ago
    Total: 192s
    #163887
  • Pipeline finished with Canceled
    8 months ago
    #163939
  • Pipeline finished with Canceled
    8 months ago
    #163947
  • Pipeline finished with Success
    8 months ago
    #164379
  • Pipeline finished with Success
    7 months ago
    #167945
  • Pipeline finished with Failed
    7 months ago
    Total: 344s
    #169631
  • Pipeline finished with Failed
    7 months ago
    Total: 173s
    #169949
  • Pipeline finished with Failed
    7 months ago
    Total: 171s
    #169959
  • Pipeline finished with Success
    7 months ago
    Total: 153s
    #170523
  • Pipeline finished with Success
    7 months ago
    Total: 157s
    #170528
  • Pipeline finished with Success
    7 months ago
    #177271
  • Pipeline finished with Skipped
    7 months ago
    #179715
  • Pipeline finished with Canceled
    7 months ago
    #182553
  • Pipeline finished with Success
    6 months ago
    Total: 262s
    #193440
  • Pipeline finished with Success
    6 months ago
    Total: 202s
    #204607
  • Pipeline finished with Success
    6 months ago
    Total: 170s
    #204812
  • Pipeline finished with Failed
    6 months ago
    #204818
  • Pipeline finished with Failed
    6 months ago
    #204819
  • Pipeline finished with Success
    6 months ago
    Total: 218s
    #204824
  • Pipeline finished with Success
    6 months ago
    #204835
  • Pipeline finished with Success
    6 months ago
    Total: 188s
    #205134
  • Pipeline finished with Success
    6 months ago
    #210699
  • Pipeline finished with Canceled
    6 months ago
    Total: 68s
    #210829
  • Pipeline finished with Success
    6 months ago
    #212422
  • Pipeline finished with Success
    6 months ago
    Total: 182s
    #212456
  • Pipeline finished with Success
    6 months ago
    Total: 182s
    #212552
  • Pipeline finished with Failed
    6 months ago
    Total: 308s
    #212856
  • Pipeline finished with Canceled
    5 months ago
    Total: 204s
    #228481
  • Pipeline finished with Failed
    5 months ago
    Total: 232s
    #228485
  • Pipeline finished with Failed
    5 months ago
    Total: 233s
    #228495
  • Pipeline finished with Failed
    5 months ago
    Total: 241s
    #230414
  • Pipeline finished with Failed
    5 months ago
    Total: 373s
    #234252
  • Pipeline finished with Success
    5 months ago
    Total: 316s
    #234264
  • Pipeline finished with Success
    5 months ago
    Total: 364s
    #234268
  • Pipeline finished with Canceled
    5 months ago
    Total: 77s
    #234273
  • Pipeline finished with Success
    5 months ago
    #236355
  • Pipeline finished with Success
    4 months ago
    Total: 214s
    #259222
  • Pipeline finished with Success
    4 months ago
    Total: 201s
    #259436
  • Pipeline finished with Success
    4 months ago
    #262477
  • Pipeline finished with Success
    4 months ago
    #270101
  • Pipeline finished with Success
    4 months ago
    Total: 291s
    #270527
  • Pipeline finished with Success
    4 months ago
    Total: 169s
    #271043
  • Pipeline finished with Success
    3 months ago
    Total: 229s
    #274949
  • Pipeline finished with Success
    3 months ago
    Total: 268s
    #274959
  • Pipeline finished with Success
    3 months ago
    Total: 154s
    #279090
  • Pipeline finished with Success
    3 months ago
    Total: 483s
    #280477
  • Pipeline finished with Canceled
    3 months ago
    Total: 294s
    #280515
  • Pipeline finished with Success
    3 months ago
    Total: 246s
    #282912
  • Pipeline finished with Success
    3 months ago
    Total: 155s
    #291104
  • Pipeline finished with Failed
    3 months ago
    Total: 266s
    #292720
  • Pipeline finished with Failed
    3 months ago
    Total: 239s
    #298281
  • Pipeline finished with Success
    2 months ago
    Total: 231s
    #303895
  • Pipeline finished with Success
    2 months ago
    Total: 381s
    #313014
  • Pipeline finished with Success
    2 months ago
    Total: 147s
    #314511
  • Pipeline finished with Skipped
    about 2 months ago
    #317170
  • Pipeline finished with Failed
    about 2 months ago
    Total: 144s
    #317486
  • Pipeline finished with Skipped
    about 2 months ago
    #318872
  • Pipeline finished with Failed
    about 2 months ago
    Total: 178s
    #319347
  • Pipeline finished with Success
    14 days ago
    Total: 140s
    #358964
Production build 0.71.5 2024