Changes between Version 3 and Version 4 of Ticket #36233, comment 7


Ignore:
Timestamp:
Mar 9, 2025, 4:46:27 AM (18 hours ago)
Author:
Hridesh MG

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #36233, comment 7

    v3 v4  
    4141As we can see, the context variable passed to quantize() expects the result of the quantization to have a precision of 16, however, if the input is 9999999999999999 (16 digits), the actual number of significant digits after the quantize operation becomes 18 (9999999999999999.00). This will raise an InvalidOperation exception, see - [https://docs.python.org/3/library/decimal.html#decimal.Decimal.quantize]
    4242
    43 The above situation can occur whenever the integral part of the number has more digits than `max_digits-decimal_places`** not just when the integer part has more than 15 digits**. The postgres backend automatically handles this situation by throwing the following error:
    44 {{{
    45 django.db.utils.DataError: numeric field overflow
    46 DETAIL:  A field with precision <max_digits>, scale <decimal_places> must round to an absolute value less than 10^<max_digits-decimal_places>.
    47 }}}
    48 
    49 SQLite however has no native Decimal Type so it has no handling for this.
    50 
    5143In the scenario where decimal_places is 0 and the input is 9999999999999999 (16 digits) the result of the quantization is 10000000000000000 (17 digits), i assume this is because of SQLite's quirk of only preserving the first 15 significant bits. This is a separate issue albeit the error is the same.
    5244
    5345----
    5446
    55 I hope the above made sense. I'm not sure what approach I should follow to fix this issue, would it suffice to prevent the user from entering a number which has more than 15 digits and check if its within `max_digit - decimal_places` and if so should it be caught during full_clean() or save()?
    56 
     47I hope the above made sense. I'm not sure what approach I should follow to fix this issue, any help would be appreciated.
Back to Top