Problem/Motivation

The upgrade from 8.x-1.14 to 8.x-1.15 appears to have changed the selection_criteria in the Content Type pattern YAML from an array to a structure. When saving a pattern the criteria are duplicated.

Steps to reproduce

When I edit an old pattern (this doesn't happen with new patterns or patterns updated during the upgrade to 8.x-1.15) and save it without making any changes, the Pathauto form duplicates the Conditions text "Content type is X".

As an example, the configuration YAML for the Course content type pattern changes from ...

selection_criteria:
  -
    id: 'entity_bundle:node'
    negate: false
    context_mapping:
      node: node
    bundles:
      course: course

... to ...

selection_criteria:
  0:
    id: 'entity_bundle:node'
    negate: false
    context_mapping:
      node: node
    bundles:
      course: course
  REDACTED_UUID:
    id: 'entity_bundle:node'
    negate: false
    context_mapping:
      node: node
    bundles:
      course: course

The configuration YML for the Blog content type pattern was updated during the upgrade to 8.x-1.15, and it behaves as expected.

Proposed resolution

The pattern config items that were updated by function pathauto_post_update_remove_uuid_config_key() seem OK. Could the logic of that function be applied to all patterns?

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork pathauto-3588582

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kenwest created an issue. See original summary.

mably made their first commit to this issue’s fork.

mably’s picture

mably’s picture

Assigned: Unassigned » berdir
Status: Active » Needs review
mably’s picture

Hi @kenwest,

Thanks for the report. The fix is up as MR !171. Tracing how the YAML in your pattern can end up with a numeric key (- list-form rather than a UUID-keyed map), one in-tree origin is the migrate source plugin at src/Plugin/migrate/source/PathautoPattern.php line 132, which wraps the migrated condition with $row->setSourceProperty('selection_criteria', [$selection_criteria]). Any pathauto pattern that came over via a Drupal-7-to-Drupal-8/9/10/11 migration ends up with that shape on disk.

Two questions:

  1. Was your CAPC pattern (or whichever site this is from) originally migrated from Drupal 7? If yes, that confirms the origin and would let us file a follow-up to fix the migrate source so future migrations produce UUID-keyed criteria from the start.
  2. Could you apply the patch from MR !171 on a copy of your environment and confirm that re-saving an affected pattern no longer duplicates the condition?

The fix has two parts: a falsy-zero check that prevents the duplication itself, and a defensive normalization that rekeys any non-UUID condition id to a UUID on first save through the edit form, so the on-disk shape matches what the rest of the codebase assumes.

kenwest’s picture

Hi @mably,

  1. Yes, the patterns were produced in a migration from D7 to D10
  2. The patch fixes the issue if the selection_criteria key is a numeric key. The "Content type is X" message is not repeated, and in the YAML the numeric key is replaced by a UUID.
  3. However, when I edit a pattern having the configuration I reported above (two identical selection criteria, one keyed with the string '0' and the other with a UUID), the issue persists when the pattern is saved. So it appears the patch doesn't handle patterns that had a numeric key before 1.15 and were edited with 1.15 before the patch was applied.
kenwest’s picture

I just read the remark "defensive normalization that rekeys any non-UUID condition id to a UUID on first save through the edit form". The point 3 in my previous comment was not the "first edit" so that might explain the failure I described. Here's what I did ...

  1. Restore Drupal site to state using pathauto 1.14
  2. Use composer to update pathauto to 1.15 and to apply patch
  3. Edit the 'course' pattern - condition text is not duplicated
  4. drush cex
  5. YAML is now keyed on a UUID
  6. Edit the YAML to duplicate the selection_criteria, but keyed on '0:'
  7. drush cim
  8. Edit the 'course' pattern - condition text is duplicated both before and after the edit
  9. YAML still has duplicated criteria
kenwest’s picture

I re-ran the test but still get the problem I describe in point 3 in #7. Here's what I did this time (this should replicate the experience of someone like me) ...

  1. Restore Drupal site to state using pathauto 1.14
  2. Use composer to update pathauto to 1.15
  3. Edit the 'course' pattern - condition text is duplicated
  4. drush cex
  5. YAML has duplicated selection_criteria - one keyed on '0:' and the other on a UUID
  6. Use composer to apply the patch
  7. Edit the 'course' pattern - condition text is still duplicated
  8. drush cex
  9. YAML still has duplicated criteria
mably’s picture

Hi @kenwest can you give a try to the latest version of the MR?

kenwest’s picture

Hi @mably,

I tested the latest version of the MR and it successfully handles the following 4 cases (these are content types each with a pattern) ...

  1. Blog - created before 1.15 and updated by the remove_uuid_config_key post-update
  2. Event - created before 1.15 but not updated by the remove_uuid_config_key post-update
  3. Course - created before 1.15 but not updated by the remove_uuid_config_key post-update - updated after 1.15 but before the MR was applied
  4. Office - created after 1.15

Before applying the patch: the Blog and Office patterns used UUID keys; the Event pattern used numeric keys; and the Course pattern duplicated numeric and UUID keys and no numeric keys.

After applying the patch, I edited each pattern and saved it with no changes. All patterns were saved with UUID keys.