Problem/Motivation

As of 11.2 an install profile I built with default content has stopped working correctly because the default content media fail with this error:

Error: Call to a member function getSource() on null in /var/www/html/web/core/modules/media/src/Entity/Media.php on line 156 #0 /var/www/html/web/core/modules/media/src/Entity/Media.php(442): Drupal\media\Entity\Media->getSource()
#1 /var/www/html/web/core/modules/media/src/MediaStorage.php(27): Drupal\media\Entity\Media->prepareSave()
#2 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php(370): Drupal\media\MediaStorage->save()
#3 /var/www/html/web/modules/contrib/default_content/src/Importer.php(310): Drupal\Core\Entity\EntityBase->save()
#4 /var/www/html/web/modules/contrib/default_content/default_content.module(15): Drupal\default_content\Importer->importContent()
#5 [internal function]: default_content_modules_installed()

Steps to reproduce

Create an installation profile that includes default content including files and media.

Proposed resolution

Fix the bug.

Remaining tasks

Fix the bug.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Comments

damienmckenna created an issue. See original summary.

damienmckenna’s picture

This is what the media item looks like:

_meta:
  version: '1.0'
  entity_type: media
  uuid: 3684febe-bcda-476e-a760-d299732d4c46
  bundle: image
  default_langcode: en
  depends:
    bd257a36-061d-451a-8369-1a48bcf2fe5b: file
default:
  status:
    -
      value: true
  uid:
    -
      target_id: 1
  name:
    -
      value: video.png
  created:
    -
      value: 1524570214
  revision_translation_affected:
    -
      value: true
  path:
    -
      alias: ''
      langcode: en
      pathauto: 1
  field_media_image:
    -
      entity: bd257a36-061d-451a-8369-1a48bcf2fe5b
      alt: ''
      title: ''
      width: 100
      height: 75

This is what the file object looks like:

_meta:
  version: '1.0'
  entity_type: file
  uuid: bd257a36-061d-451a-8369-1a48bcf2fe5b
  default_langcode: en
default:
  uid:
    -
      target_id: 1
  filename:
    -
      value: video.png
  uri:
    -
      value: 'public://media-icons/generic/video.png'
  filemime:
    -
      value: image/png
  filesize:
    -
      value: 16552
  status:
    -
      value: true
  created:
    -
      value: 1524570214
damienmckenna’s picture

I did some digging and the files did import correctly, so it seems to be just the media.

damienmckenna’s picture

damienmckenna’s picture

FWIW the media item that fails was listed as a dependency on a node.

berdir’s picture

Status: Active » Postponed (maintainer needs more info)

Our default content medias work fine. That error sounds like you're trying to import media for a bundle that doesn't exist, so you need to check when and how you import config vs default content.