Opened 2 months ago
Last modified 6 weeks ago
#36030 assigned Bug
Rendering decimal to SQL is incoherent and leads to bugs. It relays on str formating not type. — at Initial Version
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.
According to the ticket's flags, the next step(s) to move this issue forward are:
- For anyone except the patch author to review the patch using the patch review checklist and either mark the ticket as "Ready for checkin" if everything looks good, or leave comments for improvement and mark the ticket as "Patch needs improvement".