- Merge request !26[#3548416] bug: Logic to generate a new code is not avoiding collisions and is not encapsulated → (Open) created by plopesc
When creating a new wishlist, the code is generated as part of the preSave() method.
That logic is trying to avoid collisions, but in the end is not using the safe code.
Here is the code:
/** @var \Drupal\commerce_wishlist\WishlistStorageInterface $storage */
$storage = $this->entityTypeManager()->getStorage('commerce_wishlist');
$random = new Random();
$code = $random->word(13);
// Ensure code uniqueness. Collisions are rare, but possible.
while ($storage->loadByCode($code)) {
$code = $random->word(13);
}
$this->setCode($random->word(13));Even if $code is generated, a new code that might cause a collision is set.
We found it while trying to implement a custom pattern for this code, and would be great to encapsulate this logic to extend the parent class in a safer way.
Active
3.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.