Steps to repeat:
1. Enable Number module.
2. Create a new content type with a Float field type.
3. Create a new node using a value like '123.' or '9.' (w/o quotes) for the Float field type.

Expected Results:
Print an error message for invalid value. An alternative would be remove the decimal point (save '123' or '9' in the given examples).

Actual Results:
SQLException.
PDOException: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'field_number_value' at row 1: INSERT INTO {field_data_field_number} (entity_type, entity_id, revision_id, bundle, delta, language, field_number_value) 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); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 199 [:db_insert_placeholder_2] => 199 [:db_insert_placeholder_3] => teste [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 1. ) in field_sql_storage_field_storage_write() (line 451 of /path/to/drupal/modules/field/modules/field_sql_storage/field_sql_storage.module).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

generalredneck’s picture

Status: Active » Needs review
FileSize
683 bytes

I got this one...

Turns out that if we were using Decimal fields... this would work... however floats are a special case since we can't "round" them. What I ended up doing was converting the variable to a floatval. This should take care of all cases with no side-effects AFAIK.

xatiu’s picture

Issue summary: View changes

I 've issued the same problem, and the patch solved it. Could we merge this to core (number module)?
Thank you

generalredneck’s picture

If the patch still applies up the version and mark as reviewed and tested by the community. We will see if someone comes around and commits it.

Patil_kunal27’s picture

For the approach of remove the decimal point, you can use

$items[$delta]['value'] = floatval($item['value']);
or
$items[$delta]['value'] = (float)$item['value'];
or
$items[$delta]['value'] = number_format($item['value'],2);

mirsoft’s picture

Version: 7.22 » 7.50
Status: Needs review » Reviewed & tested by the community

The issue was identified and reproduced on several D7 systems on the latest Drupal 7 version to date. Confirmed the patch #1 fixed the issue.
Drupal 8 is not affected.

mirsoft’s picture

Side note: It also seems that the error behaves differently on different MySQL server settings. On one installation the exception was thrown only if "." character was inserted. On different installation, also insertions like "55." failed.

Fabianx’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Drupal bugfix target, +Needs tests

As this is a bug, we will need tests to check for this new case to ensure it does not regress again.

aerozeppelin’s picture

Tests to check for PDO errors, when saving a node having a field of type 'Float'.

The last submitted patch, 8: test-only-fail-2042411-8.patch, failed testing.

Fabianx’s picture

Version: 7.5 » 7.x-dev
chertzog’s picture

Status: Needs review » Reviewed & tested by the community

#8 is working for me.

Fabianx’s picture

Issue tags: -Needs tests +Pending Drupal 7 commit
+++ b/modules/field/modules/number/number.module
@@ -164,6 +164,15 @@ function number_field_presave($entity_type, $entity, $field, $instance, $langcod
+    // Fix for #2042411 - Float field type not validating number with decimal
+    // point but no decimal numbers.

The comment needs work, but this can be fixed on commit.

We usually don't reference the issue numbers.

Nice work!

stefan.r’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Pending Drupal 7 commit

Committed and pushed to 7.x, thanks!

  • 31864be committed on 7.x
    Issue #2042411 by aerozeppelin, generalredneck: Float field type not...

  • d9ee137 committed on 7.x
    Updated: Issue #2042411 by aerozeppelin, generalredneck: Float field...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.