1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Fixed #36030 Fixed inconsistent decimal for DIV MUL ADD and SUB operations

This commit is contained in:
greg 2024-12-22 17:29:38 +01:00
parent 890aaca91a
commit c9fbeffc0a
2 changed files with 9 additions and 19 deletions

19
.gitignore vendored
View File

@ -1,19 +0,0 @@
# If you need to exclude files such as those generated by an IDE, use
# $GIT_DIR/info/exclude or the core.excludesFile configuration variable as
# described in https://git-scm.com/docs/gitignore
*.egg-info
*.pot
*.py[co]
.tox/
__pycache__
MANIFEST
dist/
docs/_build/
docs/locale/
node_modules/
tests/coverage_html/
tests/.coverage*
build/
tests/report/
tests/screenshots/

View File

@ -61,6 +61,13 @@ class Combinable:
BITXOR = "#"
def _combine(self, other, connector, reversed):
if connector in [self.DIV, self.MUL, self.ADD, self.SUB] and isinstance(
other, (int, float, Decimal)
):
other = Value(
Decimal(str(other)),
output_field=fields.DecimalField(max_digits=20, decimal_places=10),
)
if not hasattr(other, "resolve_expression"):
# everything must be resolvable to an expression
other = Value(other)
@ -1172,6 +1179,8 @@ class Value(SQLiteNumericMixin, Expression):
def resolve_expression(
self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False
):
if isinstance(self.value, Decimal) and not self.output_field:
self.output_field = fields.DecimalField(max_digits=20, decimal_places=10)
c = super().resolve_expression(query, allow_joins, reuse, summarize, for_save)
c.for_save = for_save
return c