Creating an context object for an entity that is being deleted causes a fatal error

Created on 24 October 2018, over 6 years ago
Updated 30 January 2023, about 2 years ago

Problem/Motivation

function foo_entity_delete(EntityInterface $entity) {
  $context = EntityContext::fromEntity($entity);
}

This will fail.

Introduced in #2791269: Allow saving pre-existing references to inaccessible items โ†’

Proposed resolution

If \Drupal\Core\Entity\Plugin\Validation\Constraint\ValidReferenceConstraintValidator::validate() can't load the unchanged entity from the DB (because it no longer exists), use the one we have

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

๐Ÿ› Bug report
Status

Needs work

Version

10.1 โœจ

Component
Pluginย  โ†’

Last updated about 17 hours ago

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States tim.plunkett Philadelphia

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot โ†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review about 2 years ago
  • Status changed to Needs work about 2 years ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ameymudras

    Did a brief code review and the following comment doesn't make sense to me, I think we should reword it. Otherwise, the code looks good
    // We might use the passed entity instead of the unchanged one.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sahil.goyal

    Made change to the comment as per #30 so the comment is now quite relevant what it supposed to do.

  • last update about 2 years ago
    29,284 pass
  • Status changed to Needs review about 2 years ago
  • Status changed to Needs work almost 2 years ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Attempted to replicate this by running the code in the issue summary and I don't get any error in 10.1

    Can someone please confirm if it's still an issue and update the issue summary with additional steps

    Thanks!

  • Issue was unassigned.
  • Status changed to Closed: outdated almost 2 years ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tim.plunkett Philadelphia

    I think the codepath described by the test case (introduced in #7) was at one time relevant to how Layout Builder was working, but is not reproducible anymore in core. And I can't think of a reason why you'd need to do it in custom code either.

  • Status changed to Active about 1 year ago
  • ๐Ÿ‡ท๐Ÿ‡ดRomania amateescu

    There's still a reference in code to this issue in \Drupal\layout_builder\InlineBlockEntityOperations::handleEntityDelete(), let's see if calling isLayoutCompatibleEntity() is possible now.

  • Merge request !7106Fix @todo item. โ†’ (Open) created by amateescu
  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ท๐Ÿ‡ดRomania amateescu

    Opened a MR, let's see how it goes.

  • Status changed to Needs work about 1 year ago
  • The Needs Review Queue Bot โ†’ tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request โ†’ . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • Pipeline finished with Success
    about 1 year ago
    Total: 550s
    #124066
  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ท๐Ÿ‡ดRomania amateescu

    Hiding the patches because the MR seems to work well :)

  • Status changed to RTBC about 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Updated title and solution to mention this seems to be cleaning up a todo and use isLayoutCompatibleEntity().

  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom alexpott ๐Ÿ‡ช๐Ÿ‡บ๐ŸŒ

    Added a question the MR.

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Moving to NW for someone to test that proposal.

  • First commit to issue fork.
  • ๐Ÿ‡ง๐Ÿ‡ทBrazil brandonlira

    Hi all,
    I removed the isLayoutCompatibleEntity($entity) check before calling removeByLayoutEntity($entity), as suggested.

    Tests performed:

    PHPUnit: All tests passed successfully, with no errors found. Only pre-existing skipped tests remained unchanged.

    The change has been committed and submitted in the Merge Request. Awaiting feedback for any necessary adjustments!

    Thank you!

  • Pipeline finished with Failed
    about 1 month ago
    Total: 894s
    #451796
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    MR is 1800+ commits back.

  • Pipeline finished with Failed
    about 1 month ago
    Total: 604s
    #452469
  • ๐Ÿ‡ง๐Ÿ‡ทBrazil brandonlira

    Hi @smustgrave

    I have successfully rebased the branch with the latest changes from 11.x. The MR !7106 is now up to date, and the previous changes remain intact.

    Additionally, I noticed that one test failed, but it does not appear to be related to the changes made in this MR.

    Please let me know if you need any additional adjustments.

    Thanks!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    So reading the issue summary and title

    update InlineBlockEntityOperations::handleEntityDelete() to use isLayoutCompatibleEntity()

    Still seems to be needed.

  • ๐Ÿ‡ง๐Ÿ‡ทBrazil brandonlira

    Hi @smustgrave,

    Apologies if I might be misunderstanding something here, but I just want to clarify the intent behind this change to ensure I'm following the best approach. I'm still getting started with contributing to Drupal, and I really appreciate your guidance.

    The issue summary suggests that handleEntityDelete() should be updated to use isLayoutCompatibleEntity(), but after reviewing the implementation, I noticed that removeByLayoutEntity($entity) does not fail if the entity is not layout-compatible. Instead, it simply attempts to clean up inline_block_usage, setting layout_entity_id and layout_entity_type to NULL if applicable. If no matching records exist, nothing happens, which makes me wonder if the extra check is truly necessary.

    I just want to make sure I'm not missing something here:

    • Was there a specific issue that required adding isLayoutCompatibleEntity()?
    • Is there any scenario where calling removeByLayoutEntity() directly could cause unintended side effects?

    If the check is needed for a reason Iโ€™m not seeing, Iโ€™ll be happy to update it accordingly. Otherwise, removing it might help simplify the logic while still ensuring the cleanup happens.

    Again, thanks for your patience and feedbackโ€”I really appreciate learning from this process!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    No worries. So might help to look at the reference issue this was created from.

    Not a layout builder expert to say whatโ€™s needed or not but the summary needs to match the MR. Helps committers quickly understand a ticket

    If itโ€™s determined nothing is needed then the summary could include your findings and just a simple solution of remove the todo

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Can put back into review for more eyes but before RTBC summary will have to match

Production build 0.71.5 2024