If you have a file with no usage, and you go to admin/content/files and click the '0 places' for that record, you get a nice fatal error:
InvalidArgumentException: The entity type does not exist. in Drupal\Core\Entity\EntityManager->getControllerClass() (line 215 of /home/davereid/Sites/drupal8/core/lib/Drupal/Core/Entity/EntityManager.php).
This is because in EntityLabel::preRender() the $entity_ids_per_type variable results in the following value: array ( '' => array ( 0 => NULL, ), )
which means we attempt to load an empty entity type with an array of IDs containing one NULL value. I'm surprised this even managed to get to this case since there should not have been any results in the first place.
Comments
Comment #1
elvis2 CreditAttribution: elvis2 commentedIs this still an issue as of today? I pulled down the latest code and tried to duplicate the problem. Can you provide a screenshot?
Comment #2
jmarkel CreditAttribution: jmarkel commentedI just did a git pull on 8.x and started from scratch with a new database. I was easily able to reproduce the issue. Screenshot attached.
Steps to reproduce:
1) Create a new Article, includiing text AND a picture. Save the article
2) Edit the article - remove the picture (click the Remove button). Save the article
3) Go to .../admin/content/files
4) Click on "0 places"
5) See error mesage
Comment #3
damiankloip CreditAttribution: damiankloip commentedAdded the VDC tag, otherwise we will not see/find this :)
Yeah, it has an array of empty things like that because the base table for that view is file_managed with a left join to the file usage table. Ideally this view would use an inner join, problem solved, but we can't just change the views data like that.
Comment #4
damiankloip CreditAttribution: damiankloip commentedSo we could just fix it like this for now as I'm not sure if we have a better way for now, as we will get a record with empty values. It would be nicer to fix this on the query level though.
Comment #6
damiankloip CreditAttribution: damiankloip commentedSorry, that didn't apply.
Here is a new patch that contains that fix (probably good anyway), and a removal of the implicit relationship between file_managed and file_usage. As mentioned above, this is resulting in always using a left join, but for the single file usage view, we want this to be inner.
So if we switch to just using actual relationships, we get this flexibility.
Would be grateful if people could test this and confirm.
Comment #7
damiankloip CreditAttribution: damiankloip commentedComment #8
damiankloip CreditAttribution: damiankloip commentedThis new issue queue format is killing me :)
Comment #9
dawehnerI really like to kill implicit relationships.
Comment #10
catchShouldn't we add a test for this?
Comment #11
damiankloip CreditAttribution: damiankloip commentedI think the only feasible way to add tests for this is to just test the default file views. This should cover that. Here is a patch with just new tests and with fixes.
I was surprised to find no coverage at all for the default file views, not sure what happened when they got in? :)
Comment #12
Dave ReidWould changing this relationship mean the default file listing wouldn't display any files that don't have any usage? If so, that would be undesired.
Comment #14
damiankloip CreditAttribution: damiankloip commentedNo, I think we're good; the whole point of using the relationship instead of an implicit join (in views data) is that we can change this, and each view requires a different join. Which we can now easily do (in the UI this translates to the 'require this relationship' checkbox).
Comment #15
damiankloip CreditAttribution: damiankloip commented11: 2120839-11-PASS.patch queued for re-testing. - Random UrlTest fail.
Comment #17
slashrsm CreditAttribution: slashrsm commentedCould this work like this?
See: https://api.drupal.org/api/drupal/core%21modules%21file%21lib%21Drupal%2...
Comment #18
damiankloip CreditAttribution: damiankloip commentedOk, merged those assertion into the current FileListingTest, thanks for pointing that out! Couldn't find that initially for some reason :?
Also made the change to EntityLabel::preRender
Comment #19
slashrsm CreditAttribution: slashrsm commentedLooks good to me. Let's wait for test bot. RTBC if green as far as I'm concerned.
Comment #21
damiankloip CreditAttribution: damiankloip commentedPass patch is good.
Comment #22
dawehner+1 for the test coverage!
Comment #23
slashrsm CreditAttribution: slashrsm commentedYay! :) good job!
Comment #24
webchickReading the changes to the view, my assumption was the same as Dave's, but I tested manually and indeed files with 0 usages are showing up.
Thanks for both the bug fix, and the test! :)
Committed and pushed to 8.x.
Comment #25
damiankloip CreditAttribution: damiankloip commentedThanks.
Why do people not trust us views guys?! WE KNOW VIEWS... ;)
Comment #26
webchickOh, we know! :D I just sometimes find weirdness when manually testing things, since I don't know Views as well as you do. :)
Comment #28
Gábor HojtsyFix media tag.