Problem/Motivation

In a review of #2230909: Simple decimals fail to pass validation it was discovered that \Drupal\Core\Field\Plugin\Field\FieldType\DecimalItem::getConstraints does not contain any constraint aimed at scale and precision of decimals.

This would make it possible for a value that exceeds the precision and/or scale of a field to be submitted successfully via API and probably trigger a SQL error instead of a constraint violation or worse, no error at all.

Steps to reproduce

Proposed resolution

Move/copy the precision/scale validation from \Drupal\Core\Render\Element\Number::validateNumber to a constraint on the Decimal entity.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3300348

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

darvanen created an issue. See original summary.

darvanen’s picture

Issue tags: +Bug Smash Initiative

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

berliner made their first commit to this issue’s fork.

berliner’s picture

I have started with what I think are the necessary tests to cover entity validation with regards to precision and scale of decimal fields. I'll try to get to the implementation in the next days. If anyone else wants to go ahead, please do.

anybody made their first commit to this issue’s fork.