`Component::getVersions()` must cast all version hashes to string: 1 in 4 million probability that it fails due to all-digit version hash
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3566433. -->
Reported by: [interx](https://www.drupal.org/user/413679)
Related to !457
>>>
<h3 id="overview">Overview</h3>
<p>I encountered an issue after I added a change to a component. After clearing the cache I always got an exception: </p>
<p><strong>PHP Fatal error: Uncaught TypeError: Drupal\canvas\Entity\Component::loadVersion(): Argument #1 ($version) must be of type string, int given</strong></p>
<pre>PHP Fatal error: Uncaught TypeError: Drupal\canvas\Entity\Component::loadVersion(): Argument #1 ($version) must be of type string, int given, called in /var/www/html/web/modules/contrib/canvas/src/CanvasConfigUpdater.php on line 212 and defined in /var/www/html/web/modules/contrib/canvas/src/Entity/Component.php:526<br>Stack trace:<br>#0 /var/www/html/web/modules/contrib/canvas/src/CanvasConfigUpdater.php(212): Drupal\canvas\Entity\Component->loadVersion()<br>#1 /var/www/html/web/modules/contrib/canvas/src/CanvasConfigUpdater.php(230): Drupal\canvas\CanvasConfigUpdater->needsTrackingPropsRequiredFlag()<br>#2 /var/www/html/web/modules/contrib/canvas/src/Entity/Component.php(603): Drupal\canvas\CanvasConfigUpdater->updatePropFieldDefinitionsWithRequiredFlag()<br>#3 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(567): Drupal\canvas\Entity\Component->preSave()<br>#4 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(522): Drupal\Core\Entity\EntityStorageBase->doPreSave()<br>#5 /var/www/html/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(239): Drupal\Core\Entity\EntityStorageBase->save()<br>#6 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php(370): Drupal\Core\Config\Entity\ConfigEntityStorage->save()<br>#7 /var/www/html/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php(635): Drupal\Core\Entity\EntityBase->save()<br>#8 /var/www/html/web/modules/contrib/canvas/src/Entity/Component.php(197): Drupal\Core\Config\Entity\ConfigEntityBase->save()<br>#9 /var/www/html/web/modules/contrib/canvas/src/ComponentSource/ComponentSourceManager.php(202): Drupal\canvas\Entity\Component->save()<br>#10 /var/www/html/web/modules/contrib/canvas/src/ComponentSource/ComponentSourceManager.php(90): Drupal\canvas\ComponentSource\ComponentSourceManager->generateComponentsForSource()<br>#11 /var/www/html/web/modules/contrib/canvas/src/Hook/ComponentSourceHooks.php(53): Drupal\canvas\ComponentSource\ComponentSourceManager->generateComponents()<br>#12 [internal function]: Drupal\canvas\Hook\ComponentSourceHooks->rebuild()<br>#13 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(389): call_user_func_array()<br>#14 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(340): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}()<br>#15 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(388): Drupal\Core\Extension\ModuleHandler->invokeAllWith()<br>#16 /var/www/html/web/core/includes/common.inc(465): Drupal\Core\Extension\ModuleHandler->invokeAll()<br>#17 /var/www/html/web/core/includes/utility.inc(41): drupal_flush_all_caches()</pre><p>I confirmed that there was nothing wrong with the added property itself, it works fine in other SDC's, but not in this single one. </p>
<p>Took some digging, but I guess I got unlucky :o</p>
<p>From what I found, the component version is defined as string, like in <em>propertyVersionedConfigEntityBase::loadedVersion</em>, all generated version hashes should therefore be a strings. This is where it turned weird, it seems that the hashing function to generate the version returned a fully numeric string.</p>
<p><code> return \hash('xxh64', \json_encode($data, JSON_THROW_ON_ERROR));</code> </p>
<p>In my case it generated "5747656619415197".</p>
<p>After generation, the hash is used later on in code as an array key. If the key is fully numeric it gets converted in PHP to int, causing problems with string type hinting and schema validation down the line.</p>
<h3 id="proposed-resolution">Proposed resolution</h3>
<p>Add a safety check on the generated hashes?</p>
> Related issue: [Issue #3523841](https://www.drupal.org/node/3523841)
> Related issue: [Issue #3528362](https://www.drupal.org/node/3528362)
issue