Applying a recipe that provides content that has been trashed crashes

Created on 4 December 2024, 4 months ago

Problem/Motivation

Applying a recipe that provides content that has been trashed fails because of duplicate uuids.

Steps to reproduce

- Install drupal_cms (that applies drupal_cms_privacy_basic recipe)
- Delete the Privacy Policy node.
- ddev recipe-apply recipes/drupal_cms_privacy_basic (that tries to apply the same recipe again)

Crashes with:

  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '00d105b3-6f05-40c6-a289-3dd61c89480e' for key 'node_field__uuid__value': INSERT INTO "node" ("vid", "type", "uuid", "langcode") VALUE

Proposed resolution

When we are applying a recipe, we should apply the "ignore" context.

Remaining tasks

Find a way to apply the "ignore" context when we know we are applying a recipe

User interface changes

None.

API changes

None?

Data model changes

None

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @penyaskito
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    When applying recipes and/or when importing default_content we should trigger an event.
    Right now that only happens when a recipe has been already installed (we need an issue in core).

    We need to subscribe to that event, and apply the ignore trash context as we already do for workspaces in TrashIgnoreSubscriber::onWorkspacePrePublish.

    The problem I'm facing is that AFAIK, this context apply per request, and this content import could happen in batches. So that applied context is lost.

  • πŸ‡·πŸ‡΄Romania amateescu

    I think the problem here is only content import, not applying a recipe. So the content import process needs to dispatch a "default_content pre-import" event when starting a batch, and that's what Trash should subscribe to.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    @amateescu You are right. To be honest I think both should trigger events.

    I have a working solution locally :-)

    Just created ✨ When applying a recipe, we need to trigger an event pre importing content Active

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    Might need tests?

    Postponed on ✨ When applying a recipe, we need to trigger an event pre importing content Active . No sense to work on this anymore if we might need to rename the class or whatever. Will serve as a POC it works.

  • Pipeline finished with Failed
    4 months ago
    Total: 233s
    #359713
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    I discussed this with @tim.plunkett and @pameeela and we decided it is not a Drupal CMS stable blocker. It's a nasty bug, but likely an edge case. And besides, the fix depends on an upstream change in core that is not itself a Drupal CMS stable blocker. So by extension, this isn't either. I'm downgrading it to a release target, as it would be nice to get it fixed if core can get the requisite change into 11.1.2 (and hopefully that gets tagged before we launch 1.0.0).

  • Pipeline finished with Canceled
    4 months ago
    Total: 132s
    #376658
  • Pipeline finished with Failed
    4 months ago
    Total: 279s
    #376662
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    ✨ When applying a recipe, we need to trigger an event pre importing content Active landed.

    The final solution allows to skip uuids giving a reason, and we have information for knowing if skipping or erroring). But to be honest, I think we just should set the trash "ignore" context as that's something the importer should be taking care anyway.

  • πŸ‡·πŸ‡΄Romania amateescu

    What's the behavior of setting the inactive trash context when importing default content? Does the import process provide an error or something that it couldn't import a node because it already exists?

    I defer the decision on how to handle this issue to the Drupal CMS / Recipes initiative folks, but my impression is that we should use the new API as it was designed: skip the content that can't be imported, and provide the reason for it.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    The current behavior is a cryptic mysql error because of duplicated uuids.

    The behavior with this patch and setting inactive context is that nothing happens with this content, because recipe runner uses skip and is detected properly: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...

    If recipe runner (or any other service calling default_content import APIs) wanted to use the error behavior instead, it would have to handle the error, because with this patch the content will be detected as existing, something that doesn't happen now.

  • Pipeline finished with Skipped
    3 months ago
    #381379
  • πŸ‡·πŸ‡΄Romania amateescu

    Merged into 3.x, thanks!

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

Production build 0.71.5 2024