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).
Comment | File | Size | Author |
---|---|---|---|
#8 | 2042411-8.patch | 2.26 KB | aerozeppelin |
#8 | interdiff-2042411-1-8.txt | 1.59 KB | aerozeppelin |
#8 | test-only-fail-2042411-8.patch | 1.59 KB | aerozeppelin |
#1 | fix_float_formatting_for_decimal_and_no_following_numbers-2042411-1.patch | 683 bytes | generalredneck |
Comments
Comment #1
generalredneckI 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.
Comment #2
xatiu CreditAttribution: xatiu commentedI 've issued the same problem, and the patch solved it. Could we merge this to core (number module)?
Thank you
Comment #3
generalredneckIf 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.
Comment #4
Patil_kunal27 CreditAttribution: Patil_kunal27 as a volunteer and at Intelliswift commentedFor 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);
Comment #5
mirsoft CreditAttribution: mirsoft at Acquia commentedThe 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.
Comment #6
mirsoft CreditAttribution: mirsoft at Acquia commentedSide 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.
Comment #7
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedAs this is a bug, we will need tests to check for this new case to ensure it does not regress again.
Comment #8
aerozeppelin CreditAttribution: aerozeppelin commentedTests to check for PDO errors, when saving a node having a field of type 'Float'.
Comment #10
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedComment #11
chertzog#8 is working for me.
Comment #12
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedThe comment needs work, but this can be fixed on commit.
We usually don't reference the issue numbers.
Nice work!
Comment #13
stefan.r CreditAttribution: stefan.r commentedCommitted and pushed to 7.x, thanks!