Changes between Initial Version and Version 1 of Ticket #36233, comment 7


Ignore:
Timestamp:
Mar 9, 2025, 4:05:41 AM (25 hours ago)
Author:
Hridesh MG

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #36233, comment 7

    initial v1  
    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 In 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. So the root cause is the same for both errors. 
     43The 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{{{
     45django.db.utils.DataError: numeric field overflow
     46DETAIL:  A field with precision <max_digits>, scale <decimal_places> must round to an absolute value less than 10^<max_digits-decimal_places>.
     47}}}
     48
     49SQLite however has no native Decimal Type so it has no handling for this.
     50
     51In 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.
    4452
    4553----
Back to Top