Trigger entity validation in \Drupal\Core\DefaultContent\Importer::importContent()

Created on 19 April 2024, 7 months ago
Updated 16 May 2024, 6 months ago

Problem/Motivation

Pointed out by @larowlan in ✨ Add recipes api as experimental API to core Needs review - we don't check if the entity is valid before we save it (how Drupal).

Steps to reproduce

Proposed resolution

Validate the entity prior to saving and report it. Decide if this should lead to a recipe error or not. I think it should.
Check default content module for any existing issues about this.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

11.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

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

Merge Requests

Comments & Activities

  • Issue created by @alexpott
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ
  • First commit to issue fork.
  • Pipeline finished with Failed
    7 months ago
    Total: 437s
    #151165
  • Pipeline finished with Canceled
    7 months ago
    Total: 59s
    #151174
  • Pipeline finished with Failed
    7 months ago
    Total: 423s
    #151175
  • Pipeline finished with Failed
    7 months ago
    #151193
  • Pipeline finished with Failed
    7 months ago
    Total: 410s
    #151379
  • Status changed to Needs review 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    This was tricky, and revealed a flaw in our handling of duplicate file entities.

    Turns out file entities cannot be duplicated by URI. That's validated at the entity level. Yet we specifically test for that -- the only reason that test passed before, is because we weren't doing entity validation.

    So I refactored the file handling logic to do this, in order:

    1. If there's no physical source file to be copied, there's nothing we can do. (This is the existing behavior.)
    2. If the source file and destination file exist, but have different contents, then ensure the destination file will have a different name. (This is the existing behavior, changed slightly.)
    3. Now that we know the destination URI, check if there's a file entity that already has it. If there is, then don't import the incoming file entity -- just use the existing one, and ensure that any other entities being imported in the current batch which reference the new file entity, will actually reference the existing one.
    4. Finally, if there is no file entity for the destination URI, copy the physical file and update the URI of the file entity we're importing.

    The test coverage probably has some gaps, and I do need to write explicit coverage that validation is triggered, but this is progress...

  • Pipeline finished with Failed
    7 months ago
    Total: 411s
    #151397
  • Pipeline finished with Failed
    7 months ago
    Total: 381s
    #151472
  • Status changed to Postponed 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    I suspect the test failures here are linked to #3442024: Account switching to user 1 is now fraught β†’ , so postponing this issue on that one.

  • Status changed to Needs work 7 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ
  • Pipeline finished with Failed
    7 months ago
    Total: 331s
    #156651
  • Pipeline finished with Failed
    7 months ago
    Total: 346s
    #156657
  • Pipeline finished with Success
    7 months ago
    Total: 353s
    #156680
  • Pipeline finished with Success
    7 months ago
    Total: 333s
    #156694
  • Status changed to Needs review 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • Pipeline finished with Failed
    7 months ago
    Total: 288s
    #156712
  • Pipeline finished with Failed
    7 months ago
    Total: 345s
    #156715
  • Pipeline finished with Success
    7 months ago
    Total: 436s
    #156731
  • Status changed to Needs work 7 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Great to see this close. I think the exception needs to have the file that caused it - if possible - or if not then the uuid not the ID.

    Fixed a bug on the MR by moving the validation into the loop.

  • Status changed to Needs review 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • Pipeline finished with Failed
    7 months ago
    Total: 405s
    #157497
  • Pipeline finished with Success
    7 months ago
    Total: 343s
    #157508
  • Status changed to Fixed 7 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Committed and pushed 1736da1fcc5 to 11.x and f665255f6e7 to 10.3.x. Thanks!

    • alexpott β†’ committed f665255f on 10.3.x
      Issue #3442022 by phenaproxima, alexpott, larowlan: Trigger entity...
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Cherry-picked to ✨ Add recipes api as experimental API to core Needs review

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    This looks like a crucial addition for the "default content" functionality!

    Check default content module for any existing issues about this.

    Dare I ask … what was the outcome of this? 🫣

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    😨

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

Production build 0.71.5 2024