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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

elvis2’s picture

Is this still an issue as of today? I pulled down the latest code and tried to duplicate the problem. Can you provide a screenshot?

jmarkel’s picture

I 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

damiankloip’s picture

Issue tags: +VDC

Added 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.

damiankloip’s picture

Status: Active » Needs review
FileSize
1.63 KB

So 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.

Status: Needs review » Needs work

The last submitted patch, 4: 2120839.patch, failed testing.

damiankloip’s picture

FileSize
4.5 KB

Sorry, 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.

damiankloip’s picture

damiankloip’s picture

Status: Needs work » Needs review

This new issue queue format is killing me :)

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

I really like to kill implicit relationships.

catch’s picture

Status: Reviewed & tested by the community » Needs review

Shouldn't we add a test for this?

damiankloip’s picture

FileSize
3.55 KB
8.06 KB

I 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? :)

Dave Reid’s picture

Would 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.

Status: Needs review » Needs work

The last submitted patch, 11: 2120839-11-PASS.patch, failed testing.

damiankloip’s picture

No, 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).

damiankloip’s picture

Status: Needs work » Needs review

11: 2120839-11-PASS.patch queued for re-testing. - Random UrlTest fail.

Status: Needs review » Needs work

The last submitted patch, 11: 2120839-11-FAIL.patch, failed testing.

slashrsm’s picture

  1. +++ b/core/modules/views/lib/Drupal/views/Plugin/views/field/EntityLabel.php
    @@ -123,7 +126,10 @@ public function preRender(&$values) {
         foreach ($values as $value) {
    -      $entity_ids_per_type[$this->getValue($value, 'type')][] = $this->getValue($value);
    +      if ($type = $this->getValue($value, 'type')) {
    +        $value = $this->getValue($value);
    +        $entity_ids_per_type[$type][$value] = $value;
    +      }
         }
    

    Could this work like this?

    foreach ($values as $value) {
      if ($type = $this->getValue($value, 'type')) {
        $entity_ids_per_type[$type][] = $this->getValue($value);
      }
    }
    
  2. We already have test for file listing. There is no need to add another one. We should just add coverage for this kind of errors.

    See: https://api.drupal.org/api/drupal/core%21modules%21file%21lib%21Drupal%2...

damiankloip’s picture

Status: Needs work » Needs review
FileSize
6.5 KB
2.03 KB
2.72 KB

Ok, 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

slashrsm’s picture

Looks good to me. Let's wait for test bot. RTBC if green as far as I'm concerned.

The last submitted patch, 18: 2120839-18-FAIL.patch, failed testing.

damiankloip’s picture

Pass patch is good.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

+1 for the test coverage!

slashrsm’s picture

Yay! :) good job!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Reading 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.

damiankloip’s picture

Thanks.

Why do people not trust us views guys?! WE KNOW VIEWS... ;)

webchick’s picture

Oh, we know! :D I just sometimes find weirdness when manually testing things, since I don't know Views as well as you do. :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Gábor Hojtsy’s picture

Issue tags: -Media Initiative +D8Media

Fix media tag.