Ensure that the Index entity's dependency config schema is sorted in a consistent manner

Created on 14 June 2024, 6 months ago
Updated 6 July 2024, 6 months ago

Problem/Motivation

The config dependencies of the Index entity doesn't have a consistent order. Each dependency should be added using \Drupal\Core\Entity\DependencyTrait::addDependency() ensuring that it's sorted if it doesn't already exist in the list.

Steps to reproduce

Inspect the exported config of a search api index with multiple config/module dependencies.

Proposed resolution

Ensure the dependencies are sorted.

Remaining tasks

An update hook might be required to resave existing search index.

📌 Task
Status

Fixed

Version

1.0

Component

General code

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @codebymikey
  • Pipeline finished with Success
    6 months ago
    Total: 486s
    #198937
  • Status changed to Needs review 6 months ago
  • Pipeline finished with Success
    6 months ago
    #198947
  • 🇦🇹Austria drunken monkey Vienna, Austria

    drunken monkey made their first commit to this issue’s fork.

  • 🇦🇹Austria drunken monkey Vienna, Austria

    Thanks a lot for reporting this and already providing an MR. Looks pretty solid.

    However, I don’t think it’s necessary to fix the dependency order right away, since the dependencies are basically fine. As far as I can see, the current unreliable ordering just means that there might be nonexistent changes reported for exported configs. Doesn’t seem worth it to report a nonexistent change in order to fix that. Seems to me like it would be fine to just have this fixed and reliable starting from the next time the user actually modifies the search index.
    In case you disagree, please explain how fixing the order right away would or could be beneficial for users.

  • I just thought it made more sense to follow the common convention of having the configuration updated as part of the module update as necessary just like core did with the system_post_update_sort_all_config() hook 📌 Config export key order is not predictable, use config schema to order keys for maps Fixed , since that's one of the main reasons the ConfigEntityUpdater exists.

    This ensures the config changes are a lot more predictable and consistent if it's done once as part of the module update, so subsequent config exports will only include things the user actually changed in the index.

    the current unreliable ordering just means that there might be nonexistent changes reported for exported configs.

    I think a change in the dependency order is an existent change (just like a change in config key orders according to the schema would be).

    The update hook was useful for my use case because one of my distributions has multiple search index entities included and their dependencies needed to be automatically reordered in order to match what they should be on a clean install, otherwise they'd show up in my config diffs as a missing distribution change.

    Either way, I don't have that strong a stance on it either way if you feel it's detrimental to the DX, and can reapply the post update hook myself, but I personally find it easier if such config changes are automatically documented for the developer via the update hook, so they're aware and can choose what to do with it after the database update (keep, or ignore it)

  • Pipeline finished with Success
    6 months ago
    Total: 325s
    #204890
  • ConfigEntityUpdater currently leads to settings such as "processor_settings" to be reordered by weight rather than alphabetically as per the schema.

    This is because ConfigEntityUpdater flags the entity has having trustedData(), meaning that it should no longer do any side effects such as removing/adding processors.

    I added the explicit sorts as a fallback in case it's decided that the module should still attempt those kind of configuration changes.

  • Status changed to Fixed 6 months ago
  • 🇦🇹Austria drunken monkey Vienna, Austria

    Makes sense, agreed. I just fixed one comment and then merged.
    Thanks again!

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

Production build 0.71.5 2024