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):
- Create a new view listing node content (no displays need to be added).
- Don't touch the base view config in any way (the default "title" field will be the only field, etc.)
- 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
Comment | File | Size | Author |
---|---|---|---|
#117 | interdiff.txt | 825 bytes | lauriii |
#112 | interdiff-2628230-110-112.txt | 594 bytes | mohit_aghera |
#112 | 2628230-112.patch | 41.03 KB | mohit_aghera |
#99 | after patch applied.png | 332.05 KB | aziza_a |
#99 | before patch.png | 320.33 KB | aziza_a |
Issue fork drupal-2628230
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:
- 2628230-TEST_ONLY changes, plain diff MR !46
- 2628230-adding-file-usage changes, plain diff MR !45
Comments
Comment #2
dawehnerCan you enable the display of errors on
/admin/config/development/logging
? This could give some more information to start with.Are you sure you also don't see any kind of error in the javascript error console? Its often, especially in connection with ajax work, appearing there.
Comment #3
usrsbn CreditAttribution: usrsbn commentedSorry, maybe I was a bit unclear saying that there is no error message: I meant logging / watchdog gives me no error message. There is a message in my console telling me that ajax terminated abnormally, but as that was pretty obvious I didn't mention that.
Comment #4
cilefen CreditAttribution: cilefen commented@usrsbn Please turn off JS aggregation on the performance admin screen, get us the exact console error. Also, there may be a web server PHP you could find.
Comment #5
dawehnerThere is, if you enable it, some error message involved, quite sure about that.
Comment #6
usrsbn CreditAttribution: usrsbn commented@cilefen JS aggregation is off. Chromium console gave a bit more detail than Iceweasel. Heres the exact console error:
POST http://localhost:8080/drupal-8/admin/structure/views/ajax/add-handler/zeitungsdownload/block_1/relationship?_wrapper_format=drupal_ajax net::ERR_EMPTY_RESPONSE
Comment #7
cilefen CreditAttribution: cilefen commentedWhat is the server PHP error when that happens?
Comment #8
usrsbn CreditAttribution: usrsbn commentedToday I finally made some progress. I'm now using drupal 8.0.2 and finally UI gives me this error:
and heres my logging info:
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).
Comment #9
rjacobs CreditAttribution: rjacobs commentedI've encountered this issue several times recently as well, with multiple 8.0.x tagged releases and HEAD.
In addition to the errors logged and noted by usrsbn, the following message is printed via the views_ui (though not logged... I'm not sure if there is something distinct to my logging setup that would explain that though):
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 )
This seems to occur under several different views configurations. Adding a "file usage" relationship simply appears to be impossible without resulting in a broken handler. I'm not aware of any current workaround.
I tweaked the issue summary slightly to capture error specifics.
Comment #10
rjacobs CreditAttribution: rjacobs commentedAdditional clarification to title.
Comment #11
usrsbn CreditAttribution: usrsbn commented@rjacobs: thanks, that exactly what I get
Comment #12
LendudeTurns out none of the relationships defined in FileViewsData.php have an id set for the handler.
Did some quick manual tests and this seems to help.
But oh boy does this need some tests! (and a more generic way of adding these relationships? Hardcoded adding them only to all the known core entities? Really? Feels very D7).
Comment #13
deensdale CreditAttribution: deensdale as a volunteer commentedThanks Lendude, #12 fixed it for me in 8.0.3 and 8.1.0-beta2. My system is still in dev, so plenty of opportunity to test (and plenty of time to receive an official patch).
Comment #16
dhendriks CreditAttribution: dhendriks commentedAny progress on this?
Comment #17
dhendriks CreditAttribution: dhendriks commentedI tested the patch in #12 on Drupal 8.1.10, and it doesn't solve the problem. I still get the same error dialog, a similar SQL query error, and 21 log entries.
Comment #18
dawehnerYeah I'm also not convinced by that at all. We merge the standard relationship in there normally.
Comment #19
jptreen CreditAttribution: jptreen commentedThanks Lendude, #12 also worked for me in 8.2.1
Comment #20
Shadowcub CreditAttribution: Shadowcub commented#12 worked for me in 8.2.3. Thank you! Why isn't this fixed yet?
As a side note: It seems that the lines are off in 8.2.3; what I did was a manual patch, inserting " 'id' => 'standard' " after lines 129, 145, 164, 180, 200, 215, and 234.
Comment #21
LendudeNeeds tests and probably a better (as in, more generic) fix then the thing I did in #12. The fix in #12 is fine for people needing an instant fix, but as a real fix we want to look at something better, like what @dawehner said in #18
Comment #23
takim CreditAttribution: takim commentedI m using drupal core 8.3.2 and this patch did not fix for me the error. Anybody knows or have any more patches for it?
/Takim
Comment #25
wadmiraal CreditAttribution: wadmiraal as a volunteer and commentedRe-rolled patch for 8.4.x.
Will see if I can add some failing tests. Also, should the standard handler be set as the default (in which case, the fix should be in Views)?
Comment #26
wadmiraal CreditAttribution: wadmiraal as a volunteer and commentedThis contains a failing test for the file_to_user relationship. It can only pass if you apply the patch from #25.
Comment #28
wadmiraal CreditAttribution: wadmiraal as a volunteer and commentedThis contains a failing test for the file_to_user and user_to_file relationships. It can only pass if you apply the patch from #25.
Comment #29
LendudeLets kick the testbot into motion and see if it fails.
Comment #30
wadmiraal CreditAttribution: wadmiraal as a volunteer and commentedHold on, I'm working on 2 new tests, and refactoring the first 2 :-). I'll upload the patch in a few minutes.
Comment #31
wadmiraal CreditAttribution: wadmiraal as a volunteer and commentedThis refactors the tests, merging the 3 existing User/File relationship tests into a single Kernel test (instead of a Browser test), and adds a new Kernel test for Node/File relationships.
Again: these tests will fail unless the patch from #25 is applied.
Comment #33
wadmiraal CreditAttribution: wadmiraal as a volunteer and commentedComment #34
wadmiraal CreditAttribution: wadmiraal as a volunteer and commentedComment #35
mErilainen CreditAttribution: mErilainen at Wunder commentedFix looks good to me. Not familiar with tests so can't mark as RTBC.
Comment #36
ConradFlashback CreditAttribution: ConradFlashback commented#12 works in D8.37.
Comment #38
bewilled CreditAttribution: bewilled commentedAny plans to port this to D8.5?
Comment #39
mErilainen CreditAttribution: mErilainen at Wunder commentedIs this fixed in 8.5.0 somehow? I have one view that I know of (in addition to default files list) which has file_usage relationship and it seems to work now without the patch. Adding a new relationship for file usage doesn't print any errors either.It was the patch #31 which was failing, #25 still applies. That's why it worked for me.
Comment #40
dhendriks CreditAttribution: dhendriks commentedAny progress on getting this actually released?
Comment #41
LendudeNice work on the tests. Bit of a clean up. This merges the fix and the tests.
Comment #43
nottaken CreditAttribution: nottaken commentedI came across this bug in 8.5. A little confused if this patch will/should work in 8.5?
Comment #44
mErilainen CreditAttribution: mErilainen at Wunder commented@nottaken I'm just testing core update 8.4.6 -> 8.5.1 and the patch applies and works on 8.5.1 too.
Comment #45
UniversalDrupal CreditAttribution: UniversalDrupal commentedJust tested the patch in 8.5.1. When clicking in "adding fields" after the relationship is added, the field table where you can select the fields to be added has formatting issues, with the file fields all aligned on left and the others aligned on the right.
Comment #47
cacrody@gmail.com CreditAttribution: cacrody@gmail.com commentedThis problem keeps happening in the Drupal version 8.6.1
If the user only applies the FileViewsData.php patch , it works
Comment #48
Nathan Tsai CreditAttribution: Nathan Tsai commentedStill occurring in Drupal 8.6.2, PHP 7.0.33, & MySQL 5.7.24.
Comment #49
peterbkk CreditAttribution: peterbkk commentedI can confirm that I am getting this issue on Drupal 8.6.10 too.
Comment #50
rjdavidson CreditAttribution: rjdavidson commentedJust tried patches 25 and #41 individually on my Drupal 8.6.17 site and it did not fix the issue.
Comment #51
rjg CreditAttribution: rjg commentedOn Drupal 8.7.5 I was able to apply #25 but it did not work. #12 and #41 could not be applied.
Comment #52
cgoffin CreditAttribution: cgoffin at Sopra Steria commentedHere a patch for 8.7.*.
Comment #53
cgoffin CreditAttribution: cgoffin at Sopra Steria commentedThere were some changes that didn't belong in the patch I added. I removed them from the patch.
Comment #54
Chris Matthews CreditAttribution: Chris Matthews as a volunteer and at City of Oaks Design commentedComment #55
shubhangi1995Comment #56
shubhangi1995Hi all,
The patch (2628230-53.patch) has been tested against drupal core version 8.7.7
file relationship before applying the patch:
file relationship after applying the patch :
Comment #57
shubhangi1995Comment #60
shubhangi1995patch applied successfully
Comment #61
shubhangi1995Comment #63
StefanieB CreditAttribution: StefanieB commented#53 applied to Drupal 8.8.1 fixes the problem.
Comment #64
alexpottIt looks like #53 removed the test coverage that's in #41 - we need that test coverage in order to commit this fix and ensure we don't break this again.
This is at least a major bug - you can cause your site to error through normal operation.
Comment #65
shubhangi1995Hi @alexpott, the test cases from #41 have been added to the patch from #53 and tested against drupal 8.8.1 .
it works fine.
2628230-65.patch
Comment #66
shubhangi1995Comment #67
sense-designI can confirm, the patch from #66 works for my view file relationship.
After applying the path, clear the cache and add the relationship.
Comment #68
shubhangi1995Comment #69
mmi.cse CreditAttribution: mmi.cse as a volunteer commented#53 (https://www.drupal.org/project/drupal/issues/2628230#comment-13213379) worked for me on Drupal core 8.8.3. #65 was failing to apply that patch using composer.
Comment #70
fox_01 CreditAttribution: fox_01 commented#53 works for me too. i have drupal 8.8.2
Comment #71
jamesfk CreditAttribution: jamesfk at Website Express Ltd. commentedAnother +1 for #53 on 8.8.1 - thank you :)
Comment #72
shubhangi1995Comment #73
young74xxxx CreditAttribution: young74xxxx commentedWorks on 8.8.6. After applying patch, must clear the cache to make it work.
Comment #75
junaidpvPatch from #65 does not apply to branch 8.8.x, not even to 8.8.1 tag. It looks like it got corrupted. However, I see it is exactly same as #53 except extra test cases and #53 still applies to current 8.9.x.
Comment #76
Devendra Mishra CreditAttribution: Devendra Mishra commented#53 worked for me with 8.9.2. Thanks
Comment #77
JAINV18 CreditAttribution: JAINV18 as a volunteer commented#53 worked for me with 8.9.8. Thanks.
This is such a important issue and must be resolved in Core 8.9.x
Comment #78
LendudeDidn't even open the patch file in #65 but since it is 18k and the patch in #41 is 40k, I'm pretty sure it's still missing things......Oops, should have opened it! The old patch also included a move from simpletest to phpunit, sorry!
Comment #80
LendudeStarted from scratch with #41 cause as far as I can tell all sorts of things got lost in other patches. Rerolled and refactored all the simpletest stuff. The file that gets removed is a test case that is moved from a functional test to the new kernel test, so no coverage is lost there, just some testbot run time won.
Opened an MR for this.
Comment #82
LendudeOpened up a branch/MR for test-only, not sure yet if that is the best way to handle test-only
Comment #83
ramonma1989#53 works for me. i'm using drupal 8.9.13
Comment #84
Mirzero CreditAttribution: Mirzero as a volunteer commentedI ran into this error in 9.1.10 also.
I couldn't use the patch from #53 directly as the file is now slightly different...
but adding the ID to all of the defined relationships appears to have fixed everything (with cursory testing).It looks like this patch alone isn't enough. It lets me add the file relationship properly, but then the view query starts to throw errors.
Using PostreSQL - looks like it's some kind of conversion issue... but I'm a bit out of my depth here.
Comment #85
aitala CreditAttribution: aitala commentedI'm running into this in Drupal 9.2.3
I'd try the patch in #53, but....
Comment #88
apadernoComment #89
DamirKhasanov CreditAttribution: DamirKhasanov commentedthe problem is not solved
I m use Drupal 9.3.5, php 7.3 or 8.0
Adding File Usage "File" relationship results in broken/missing
how do I solve it?
Comment #91
cafuego CreditAttribution: cafuego at United Nations commentedThe patch from #53 applies fine to the current Drupal 9; remember to do a container rebuild after applying it.
How about just adding that patch to the next release, instead of keeping a major bug open for seven years because there is no test? How is that worse than actual broken functionality?
Comment #92
petiar CreditAttribution: petiar as a volunteer commentedPatch #53 works on 9.4.5. What can we do to get this merged?
Comment #93
cilefen CreditAttribution: cilefen commentedIt looks like we need tests someone already wrote and the patch that everyone uses integrated into a single patch or a merge request.
Comment #95
sandip27 CreditAttribution: sandip27 as a volunteer commentedIt's been 7 years to this issue and seems its yet not fixed ? Weird.. I am on Drupal 9.4.8 and I am still facing this issue.. Any chance of getting the issue fixed soon ?
Comment #96
alfattal CreditAttribution: alfattal as a volunteer commentedPatch in #53 applied successfully on Drupal 9.5.3, PHP 8.0.28
Comment #97
apadernoThere are no patches in comment #53.
It is not clear why this issue has been changed to Needs work, but a comment that says the patch applies to Drupal 9.5 is not sufficient to mark the issue as Reviewed & tested by the community, especially because this is a Drupal 10 issue, now.
Comment #98
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #99
aziza_a CreditAttribution: aziza_a at Srijan | A Material+ Company commentedAdding the patch again for 10.1.x
The patch of #53 applies properly on 10.1.x
adding before and after patch images, for more clarity
Comment #100
aziza_a CreditAttribution: aziza_a at Srijan | A Material+ Company commentedComment #101
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis 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.
Comment #102
ilfelice CreditAttribution: ilfelice commentedHowdy,
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.
Comment #103
crutch CreditAttribution: crutch commented#99 or 53 fixes the issue for 9.5.9 when applied manually
Comment #105
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedSummarizing 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.
Re-roll #65 also seems missing certain things.
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.
Comment #106
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedComment #107
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedComment #110
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedI 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.
Comment #112
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commentedRemoving depredations.
Comment #113
nubeli CreditAttribution: nubeli as a volunteer and at Freeform Solutions commentedI'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.
Comment #114
smustgrave CreditAttribution: smustgrave at Mobomo commented11.x is the current development branch. All code is committed there first and case by case backported to previous versions.
Comment #117
lauriiiThe 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.
Comment #118
SpokjeThis commit has broken HEAD on 11.x and 10.1.x for pgsql only.
TestBot merrily gives us the middle finger with:
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.
Comment #119
SpokjeComment #120
lauriiiIt 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.
Comment #121
lauriiiPosted a patch in a follow-up issue: #3364621: Drupal\Tests\file\Kernel\Views\RelationshipNodeFileDataTest fails on HEAD with PostgreSQL.