Deleting media references causes InvalidComponentException and AssertionError
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3590029. -->
Reported by: [danepowell](https://www.drupal.org/user/339326)
>>>
<h3 id="overview">Overview</h3>
<p>If you reference a media entity from a region (or other config component) and then delete the referenced entity, it causes at least two types of errors.</p>
<p>On the page itself, you'll get an InvalidComponentException, which is ugly but recoverable. If you try to run canvas_post_update_0016_page_region_component_inputs_must_be_arrays, you'll get a nastier error that crashes updates:</p>
<pre>[error] AssertionError: assert(Inspector::assertAllObjects($referenced_content_entities, FieldableEntityInterface::class)) in assert() (line 210 of /var/www/html/docroot/modules/contrib/canvas/src/PropExpressions/StructuredData/ReferenceFieldTypePropExpression.php) #0 /var/www/html/docroot/modules/contrib/canvas/src/PropExpressions/StructuredData/ReferenceFieldTypePropExpression.php(210): assert()</pre><p>Steps to reproduce:</p>
<ol>
<li>Install Canvas 1.3.3</li>
<li>Edit a page region, such as the header, and add an image component with an actual image reference</li>
<li>Go to the media library and delete the referenced image</li>
<li>Revisit the page, see an InvalidComponentException in the header region</li>
<li>Install Canvas 1.4.0 and run drush updb</li>
<li>Observe an AssertionError</li>
</ol>
<p>For reference, here's what the region with the media reference looks like <em>after</em> the entity is deleted:</p>
<pre>ddev drush cget canvas.page_region.astral.header <br><br>uuid: f1e2bf9c-6ca1-4102-8bf7-573cf957bb45<br>langcode: en<br>status: true<br>dependencies:<br> config:<br> - canvas.component.js.header<br> - canvas.component.js.image<br> - canvas.component.js.logo<br> - canvas.component.js.main_navigation<br> - field.field.media.image.media_image<br> - image.style.canvas_parametrized_width<br> - media.type.acquia_dam_image_asset<br> - media.type.image<br> content:<br> - 'file:file:9dbfd988-3286-495e-87c0-90383984e3d3'<br> - 'media:image:93809c00-387a-446d-b8ca-d4adde378084'<br> module:<br> - acquia_dam<br> - file<br> - media<br> theme:<br> - astral<br>_core:<br> default_config_hash: ibBobeG3N57rxkjWfMklXLGPTkqeW-1BSPEwfEqB2fE<br>id: astral.header<br>region: header<br>theme: astral<br>component_tree:<br> 0:<br> uuid: 68fdccf3-114d-446d-bd10-8a8b6005a612<br> component_id: js.header<br> component_version: 043cb73114a3bf3f<br> inputs: '{"displaySearchForm":true}'<br> '0:logo:0':<br> parent_uuid: 68fdccf3-114d-446d-bd10-8a8b6005a612<br> slot: logo<br> uuid: 9bc3c4e7-81e1-41ef-ba40-061561d358ef<br> component_id: js.logo<br> component_version: 8fe3be948e0194e1<br> inputs: '[]'<br> '0:menu:0':<br> parent_uuid: 68fdccf3-114d-446d-bd10-8a8b6005a612<br> slot: menu<br> uuid: 7d543abc-9be9-4353-b940-38dfa578dd6a<br> component_id: js.main_navigation<br> component_version: 8fe3be948e0194e1<br> inputs: '[]'<br> 1:<br> uuid: ffdc886f-9dd1-4df1-bdf1-057e324a6cfa<br> component_id: js.image<br> component_version: f312cd1f9fe0bcf0<br> inputs: '{"image":"1"}'</pre><h3 id="proposed-resolution">Proposed resolution</h3>
<p>The attached patch should fix it but I have no idea if it's the best solution.</p>
<h3 id="ui-changes">User interface changes</h3>
issue