-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
Milestone
Description
Migrated issue, originally created by Anonymous
(original reporter: ged) This is probably not new but I just got bitten by it... I think that having "asdecimal" defaults to True in Numeric is both (usually) useless and harmful because if the DBAPI is returning floats, you already lost precision, and converting them to Decimal won't help with the precision, so it does not do any good. Furthermore, it is harmful in two ways:
- it will slow down the application quite a bit (decimal.Decimal is pure Python for now so it's at least 10x slower than floats). It's usually worth it for the sake of accuracy, but when you have already lost the accuracy, it only makes sense in very few cases.
- more importantly, it hides the lost precision to the user: the user defines a NUMERIC on the DB side and works with Decimal in his Python code, so he thinks he's on the safe side for accuracy? Wrong! He gets the rounding errors anyway behind his back.
Now, there are a few ways to fix this problem:
- change the default value to False (with its current meaning) or None (see ticket Behavior for Numeric.asdecimal=False is different than expected in many dialects #1624).
- put a BIG FAT warning in the documentation.
- add a runtime warning if the DBAPI is not returning Decimals. Would need a way to turn off the warning.