ConfigEntityQuery::recursiveCmp() triggers "Undefined array key weight" for config entities without weight
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3576096. -->
Reported by: [s-jack](https://www.drupal.org/user/655916)
Related to !659
>>>
<h3 id="overview">Overview</h3>
<p> When upgrading Canvas from 1.0.3 to 1.2.0, or when clearing caches with<br>
`drush cr` after the upgrade, a large number of PHP warnings are triggered:</p>
<p> [warning] Undefined array key "weight" ConfigEntityQuery.php:32</p>
<p> The warnings appear during cache clears, module uninstalls, and any other<br>
operation that triggers config entity queries with sorting, including<br>
operations driven by third-party modules such as Admin Toolbar.</p>
<p> The full stack trace points to:</p>
<p> Drupal\canvas\CoreBugFix\ConfigEntityQuery->recursiveCmp() (line 32)</p>
<p><strong>Original report</strong><br>
When updating from 1.1.1 to 1.2.0 via Composer, and again when clearing the cache with Drush, a large number of warnings are displayed.<br>
I failed to note the warnings during the Composer update and have forgotten them.<br>
Below are the warnings from the cache clear.</p>
<blockquote><p>[warning] Undefined array key "weight" ConfigEntityQuery.php:32<br>
[warning] Undefined array key "weight" ConfigEntityQuery.php:32<br>
[warning] Undefined array key "weight" ConfigEntityQuery.php:32<br>
[warning] Undefined array key "weight" ConfigEntityQuery.php:32<br>
[warning] Undefined array key "weight" ConfigEntityQuery.php:32<br>
[warning] Undefined array key "weight" ConfigEntityQuery.php:32<br>
[warning] Undefined array key "weight" ConfigEntityQuery.php:32<br>
[warning] Undefined array key "weight" ConfigEntityQuery.php:32
</p></blockquote>
<p>ENV: core 11.3.3, drush 13.7.1</p>
<h3 id="proposed-resolution">Proposed resolution</h3>
<p> The `recursiveCmp()` method in `src/CoreBugFix/ConfigEntityQuery.php` accesses<br>
`$a[$field]` and `$b[$field]` unconditionally (line 32). When the sort field is<br>
`weight`, and the config entity type being sorted (e.g. media types, node types)<br>
does not define a `weight` key, PHP 8 emits an "Undefined array key" warning.</p>
<p> The fix should guard against missing keys before comparing, for example using<br>
`isset()` or `??` null-coalescing before accessing `$a[$field]` / `$b[$field]`<br>
in `recursiveCmp()`. This regression was introduced in #3571997.</p>
<h3 id="ui-changes">User interface changes</h3>
> Related issue: [Issue #2862699](https://www.drupal.org/node/2862699)
issue