New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when loading specific values in fields of type {:map, :float} #2637
Comments
It's curious that the integration test fails on pg but passes on mysql. |
@wojtekmach good point! but actually I didn't add a value for field to a test case for mysql, just for pg 🤔 |
@tallysmartins |
It seems this is an issue with how postgresql handles JSON with floats in exponential notation. # create table foo(map jsonb);
CREATE TABLE
# insert into foo(map) VALUES ('{"foo": 416500.0}');
INSERT 0 1
# insert into foo(map) VALUES ('{"foo": 4.165e5}');
INSERT 0 1
# SELECT * FROM foo;
map
-------------------
{"foo": 416500.0}
{"foo": 416500}
(2 rows) |
@michalmuskala the worst part is that Postgres is semantically correct, there are no integers/floats in JSON. I guess we need to do casting here on Ecto side. |
Should we do for |
@michalmuskala if it fixes the bug, sure. :) We may need to do a couple extra things though. |
Any chance that this problem is also happening with {:array, :float}? I have a issue with an array of floats sometimes failing to be inserted. (Elixir 1.7.3, ecto, 2.2) |
Environment
Current behavior
When I have a schema with a field of type
{:map, :array
}, some values are parsed to exponential floats and are saved as integers in the database.For example,
%{"50" => 416500.0}
fails, because it is saved as an integer 416500, even afterFloat.parse(416500)
, which returns an exponential form for it. I don't know if it has something to do with the jsonb fields, but for simplefloat
fields it works.I've added an example to ecto integration tests that shows the break point. See this commit tallysmartins@5048199 and the correspondent build on Travis-ci
Expected behavior
Save and load the field the same way as simple float field.
The text was updated successfully, but these errors were encountered: