user_update_10000 causes exported permissions to be numerically keyed

Created on 13 February 2023, almost 2 years ago
Updated 15 February 2023, over 1 year ago

Problem/Motivation

After upgrading to Drupal 10, some permissions on my roles were removed by user_update_10000, the resulting config object had numeric keys on the permissions array causing the config export diff to look something like this:

Update hook was migrated from a post update in #3319845: user_post_update_update_migrated_roles_followup() needs to be a hook_update_N β†’

$ git diff
diff --git a/config-export/user.role.authenticated.yml b/config-export/user.role.authenticated.yml
index f32cd7f0..201966e7 100644
--- a/config-export/user.role.authenticated.yml
+++ b/config-export/user.role.authenticated.yml
@@ -15,12 +15,12 @@ label: 'Authenticated user'
 weight: 1
 is_admin: false
 permissions:
-  - 'access content'
-  - 'cancel account'
-  - 'execute default arbitrary graphql requests'
-  - 'flag learning_page_read'
-  - 'view media'
+  0: 'access content'
+  1: 'cancel account'
+  2: 'execute default arbitrary graphql requests'
+  3: 'flag learning_page_read'
+  4: 'view media'

Steps to reproduce

  1. Have roles with non existent permissions
  2. Upgrade to D10 and run db updates
  3. Export config

Proposed resolution

Wrap $permissions in array_values

πŸ› Bug report
Status

Closed: duplicate

Version

10.1 ✨

Component
User moduleΒ  β†’

Last updated about 19 hours ago

Created by

πŸ‡¦πŸ‡ΊAustralia acbramley

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

Comments & Activities

  • Issue created by @acbramley
  • @acbramley opened merge request.
  • Status changed to Needs review almost 2 years ago
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Not sure if this is testable, but this fixes it for me.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Bumping this to critical, it's probably not data-loss as such, but it makes it a lot harder to review the config changes as a result of the update.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Pretty janky test coverage but it fails without the fix

    1) Drupal\Tests\user\Functional\Update\UserUpdateRoleMigrateTest::testRolePermissions
    Failed asserting that two arrays are equal.
    --- Expected
    +++ Actual
    @@ @@
     Array (
         0 => 0
         1 => 1
    -    2 => 2
    -    3 => 3
    -    4 => 4
    -    5 => 5
    -    6 => 6
    +    2 => 3
    +    3 => 4
    +    4 => 5
    +    5 => 6
    +    6 => 7
     )
    
  • Status changed to RTBC almost 2 years ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    I don't have any better ideas on the test coverage, better janky than nothing, especially when it's only got to last (but do it's job very well in the meantime) until Drupal 11.

  • Status changed to Closed: duplicate almost 2 years ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    There is a much better fix for this. This is a duplicate of πŸ› Role permissions not sorted in config export Fixed and that issue has a better fix that results in this being fixed in more siutations.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Thanks @alexpott I didn't even think of that approach.

Production build 0.71.5 2024