diff options
| author | Samriddha9619 <sumitkumartripathi0@gmail.com> | 2026-01-20 01:38:34 +0530 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-01-28 17:04:39 -0500 |
| commit | 2831eaed797627e6e6410b06f74dadeb63316e09 (patch) | |
| tree | 2662cec2d329d5407be113b9c8bb25d149c5a884 /django/db/backends/sqlite3/operations.py | |
| parent | e61a54d306ec069826b53bfec0b56d9ab3199257 (diff) | |
Fixed #36233 -- Avoided quantizing integers stored in DecimalField on SQLite.
Co-authored-by: Simon Charette <charette.s@gmail.com>
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
Diffstat (limited to 'django/db/backends/sqlite3/operations.py')
| -rw-r--r-- | django/db/backends/sqlite3/operations.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/django/db/backends/sqlite3/operations.py b/django/db/backends/sqlite3/operations.py index 23c17054d2..18ff204ae3 100644 --- a/django/db/backends/sqlite3/operations.py +++ b/django/db/backends/sqlite3/operations.py @@ -300,10 +300,15 @@ class DatabaseOperations(BaseDatabaseOperations): value = parse_time(value) return value + @staticmethod + def _create_decimal(value): + if isinstance(value, (int, str)): + return decimal.Decimal(value) + return decimal.Context(prec=15).create_decimal_from_float(value) + def get_decimalfield_converter(self, expression): # SQLite stores only 15 significant digits. Digits coming from # float inaccuracy must be removed. - create_decimal = decimal.Context(prec=15).create_decimal_from_float if isinstance(expression, Col): quantize_value = decimal.Decimal(1).scaleb( -expression.output_field.decimal_places @@ -311,7 +316,7 @@ class DatabaseOperations(BaseDatabaseOperations): def converter(value, expression, connection): if value is not None: - return create_decimal(value).quantize( + return self._create_decimal(value).quantize( quantize_value, context=expression.output_field.context ) @@ -319,7 +324,7 @@ class DatabaseOperations(BaseDatabaseOperations): def converter(value, expression, connection): if value is not None: - return create_decimal(value) + return self._create_decimal(value) return converter |
