Call to a member function id() on null
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3538373. --> Reported by: [andrei.vesterli](https://www.drupal.org/user/1453966) Related to !20 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>There is a crash for <code>/jsonapi/carts</code> endpoint when this module is enabled. It looks like there might be arrays with entities, but the entity item might be NULL.<br> See, <code>createCollectionDataFromEntities</code> and <code>$entities</code> array for more context.<br> Here is the crash result:<br> <img src="https://www.drupal.org/files/issues/2025-07-28/500_crash_0.png" alt="500 Crash"></p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p>1. Enable the module jsonapi_resource<br> 2. Enable the module commerce_api<br> 3. Use the API endpoint <code>jsonapi/carts</code> when the cart is empty<br> 4. See the crash with the message above.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Write a patch for covering then the <code>$entity</code> variable from <code>createCollectionDataFromEntities</code>, which is <code>NULL</code> instead of an actual entity. This validation should be covered here and not inside the commerce_api module.</p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <p>Write the patch.</p> <h3 id="summary-ui-changes">User interface changes</h3> <p>No.</p> <h3 id="summary-api-changes">API changes</h3> <p>No.</p> <h3 id="summary-data-model-changes">Data model changes</h3> <p>No.</p>
issue