Opened 11 months ago
Last modified 7 months ago
#36030 assigned Bug
Rendering decimal to SQL is incoherent and leads to bugs. It relays on str formating not type. — at Initial Version
| Reported by: | Bartłomiej Nowak | Owned by: | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | division decimalfield |
| Cc: | Bartłomiej Nowak | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | yes |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description
When I am using Decimal at Python level, I expect to use numeric type on database level. But it seems to depend on string formatting of decimal itself instead of type of object.
See examples:
Decimal(1000.0) --> will render as 1000 at query and will be INT on db level.
Decimal(1000) --> will render as 1000 at query and will be INT on db level.
Decimal("1000.0") -> will render as 1000,0 at query and will be NUMERIC on db level.
models.Value(1000.0, output_field=DecimalField()) -> will render as 1000 at query and will be INT on db level.
models.Value(1000.0) (no decimal provided as above) -> will render as 1000,0 at query and will be NUMERIC on db level.
It leads to bugs, cuz at DB LVL, INT / INT is also INT (2/3 = 0), and I doubt anyone who provides decimal there, excepts that behavior.