Site breaking when price field is provided the out of range values

Created on 19 June 2024, 5 months ago
Updated 18 July 2024, 4 months ago

Site breaking when price field is provided the out of range values

1. Create a product and add price in the variation '99999999999999'
2. Now save the product
3. Site will give below error

Drupal\Core\Entity\EntityStorageException: SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'price__number' at row 1: INSERT INTO "commerce_product_variation_field_data" ("variation_id", "type", "langcode", "uid", "status", "product_id", "sku", "title", "list_price__number", "list_price__currency_code", "price__number", "price__currency_code", "created", "changed", "default_langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14); Array ( [:db_insert_placeholder_0] => 2 [:db_insert_placeholder_1] => event_registration [:db_insert_placeholder_2] => en [:db_insert_placeholder_3] => 1 [:db_insert_placeholder_4] => 1 [:db_insert_placeholder_5] => 2 [:db_insert_placeholder_6] => 56667hghgv [:db_insert_placeholder_7] => Demo Event on Healthcare [:db_insert_placeholder_8] => [:db_insert_placeholder_9] => [:db_insert_placeholder_10] => 99999999999999 [:db_insert_placeholder_11] => JPY [:db_insert_placeholder_12] => 1718688095 [:db_insert_placeholder_13] => 1718788212 [:db_insert_placeholder_14] => 1 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

🐛 Bug report
Status

Needs review

Version

2.39

Component

Price

Created by

🇮🇳India Deepesh151086

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

Comments & Activities

  • Issue created by @Deepesh151086
  • 🇮🇱Israel jsacksick

    This isn't really a "major" issue as entering a huge price like this is probably affecting demo sites or people just trying random things... But still, this should be fixed and we shouldn't crash like this.

  • 🇮🇳India Deepesh151086

    Hi @jsacksick we are doing the validation in commerce/modules/price/src/Element/Number.php. I am getting null while dumping $element['#max']. I am not sure where from we are getting this value. If we may set this value according the 'decimal' datatype field
    ( decimal(19,6) ) in this file , we can run the validation on max digit in price.

  • Status changed to Needs review 4 months ago
  • 🇮🇱Israel jsacksick

    Core suffers from the same problem... Not sure what is the best way of fixing this...
    You can reproduce the same issue with the number field type, specifying the same precision / scale.

    Got the following error:

    Numeric value out of range: 1264 Out of range value for column 'field_test_decimal_value'

    We could add a try catch block around the $save_return = $this->entity->save(); in ProductVariationForm, but not convinced this is the right fix as we're supposed to just save the entity from there...

    The attached patch is setting the #max value, but I don't really like this fix.

Production build 0.71.5 2024