Compare update configurations by equality

Created on 19 December 2019, over 4 years ago
Updated 31 January 2023, over 1 year ago

Imagine we generated this config file programatically:

system.theme.yml:

admin: seven
langcode: en
default: starterkits

In active config we have:

admin: seven
default: starterkits
langcode: en

The order is not the same but keys and values are fine, however drupal tell me that there are differences.
I check the code in core/lib/Drupal/Core/Config/StorageComparer.php:

  protected function addChangelistUpdate($collection) {
    $recreates = [];
    foreach (array_intersect($this->sourceNames[$collection], $this->targetNames[$collection]) as $name) {
      $source_data = $this->getSourceStorage($collection)->read($name);
      $target_data = $this->getTargetStorage($collection)->read($name);
      if ($source_data !== $target_data) {
...

This line if ($source_data !== $target_data) {, compares by identity:
$a === $b is TRUE if $a and $b have the same key/value pairs in the same order and of the same types.

If we change from:

if ($source_data !== $target_data) {

to:

if ($source_data != $target_data) {

Drupal do not see changes with the example shown above, how I expect.

We compare by equality:
$a == $b is TRUE if $a and $b have the same key/value pairs.

Here i upload a patch for that.

What do you think?

Source:
https://www.php.net/manual/en/language.operators.array.php
https://stackoverflow.com/questions/5678959/php-check-if-two-arrays-are-...

πŸ› Bug report
Status

Closed: won't fix

Version

10.1 ✨

Component
ConfigurationΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΎUruguay rpayanm

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    To me this is a won't fix as #2 mentions losing type comparison.

    If still a valid bug then a test case should be added to show this issue.

    Thanks

Production build 0.71.5 2024