Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
sqlite db driver
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
29 Jul 2015 at 13:30 UTC
Updated:
18 Aug 2015 at 13:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
alexpottThis is a float precision issue - mysql and postrges by default are 4 bytes but sqlite is 8.
Comment #2
alexpottSo let's test the 'number_formatter' rather than the database backend. But to be honest this issue makes me think we should remove the float field because its behaviour is so unpredictable.
This passes on pgsql, mysql and sqlite.
Comment #3
alexpottAlternatively we could just make all float fields big. Which would have the advantage of making float fields less surprising.
Comment #4
amateescu commentedAnother option would be to add some hand-holding code for the float field type in the 'number' widget.
Comment #5
alexpott@amateescu I'm not sure what you mean?
Comment #6
amateescu commentedI was thinking of something like this.
Comment #7
alexpottBut this does not work as you expect :)... 3.141 would be stored correctly in all engines in HEAD. The point can float :)
Comment #8
amateescu commentedRight, it was just an idea and the patch was to show you what I mean :P
I think that the patch in #3 is most likely the better option here.
Comment #10
amateescu commentedI should've posted a -do-not-test patch :/ #3 is RTBC if it passes on all three db drivers.
Comment #11
amateescu commentedI added DrupalCI test requests for #3 and NumberFieldTest passed on both:
https://dispatcher.drupalci.org/job/default/3422/consoleFull (sqlite)
https://dispatcher.drupalci.org/job/default/3423/consoleFull (postgres)
Comment #12
alexpottJust uploading #3 again so that the patch @amateescu rtbc'd is last.
I think 4 byte floats are designed to cause user frustration and we should consider either removing the field or making it be double instead. I have no idea how to explain to a user that 10000.1 and 3.141 are stored without alteration but 1234.5678 is stored as 1234.57. Moving to doubles mitigates this problem to a certain extent but I still wonder if we should just ditch floats in favour of decimals.
Testing the update path once a float field exists with data has shown something interesting. The update appears to be successful but it is not - the float is not changed to a double - and nothing is reported to the user. And then the update does not show up again! If there is no data the update works and the float is changed to a double as expected. I think in this instance we will need to write an upgrade function to handle the data change.
Comment #13
alexpottI think given the issues around this in order to have sqlite tests pass I think we should commit #2. Since that passes on all dbs and tests our code rather than database differences.
Comment #14
alexpottOpened:
as followups.
Comment #15
amateescu commentedAgreed :)
Comment #16
catchWith the two follow-ups I think this is OK. Committed/pushed to 8.0.x, thanks!