coaster icon indicating copy to clipboard operation
coaster copied to clipboard

Be consistent with use of decimal in JsonDict column

Open jace opened this issue 9 years ago • 1 comments
trafficstars

In coaster.sqlalchemy.JsonDict line 595, we use simplejson with use_decimal=True to parse non-integer numbers as Decimal instead of float. While this is a good idea because of the general unreliability of floats, it is inconsistent: this line is not reached when using PostgreSQL >= 9.2 with Psycopg2 >= 2.5. Psycopg2 does its own JSON decoding then and does not use Decimal by default.

Psycopg2 allows customisation of the way it handles JSON. This customisation can be applied at the connection or cursor level, but not per column, so the customisation code does not belong in JsonDict. Instead, it should be an interface Coaster provides per-app. JsonDict can then use this interface to parse JSON in a manner identical to what Psycopg2 would have done.

jace avatar Dec 13 '15 09:12 jace

Unit tests are also required to confirm decimal handling behaviour is consistent.

jace avatar Dec 13 '15 09:12 jace