Changes between Initial Version and Version 4 of Ticket #36030


Ignore:
Timestamp:
Dec 20, 2024, 8:40:48 AM (2 months ago)
Author:
Bartłomiej Nowak
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #36030 – Description

    initial v4  
    1111It 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.
    1212
     13=============
     14I am using Postgres.
     15
     16{{{
     17SomeModel.objects.create(some_field_of_type_int=2)
     18sm = SomeModel.objects.annotate(x=F("some_field_of_type_int") / Decimal(3.0)).get()
     19sm.x # returns 0
     20}}}
     21
     22It will render Decimal of 3.0 to the query as 3 (INT). Because str(...) from Decimal(3.0) returns 3. (See cases at description)
     23At python is not a problem, but at database it is, cus it breaks types. Calculation of two INTs at postgres, will return int as well, which is in this case 0, instead of 0.6666, which database would produce, if Django would render 3.0 instead of 3.
     24
     25Therefore, Django will return Decimal('0'), which I consider as Bug. This is not what anyone suppose to get.
     26=============
Back to Top