Commit 267a1dcd authored by Josh Smeaton's avatar Josh Smeaton Committed by Tim Graham
Browse files

Fixed #23941 -- Removed implicit decimal formatting from expressions.

parent e2868308
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -1195,8 +1195,6 @@ class BaseDatabaseOperations(object):
        Transform a decimal.Decimal value to an object compatible with what is
        expected by the backend driver for decimal (numeric) columns.
        """
        if value is None:
            return None
        return utils.format_number(value, max_digits, decimal_places)

    def year_lookup_bounds_for_date_field(self, value):
+1 −3
Original line number Diff line number Diff line
@@ -312,9 +312,7 @@ WHEN (new.%(col_name)s IS NULL)
        return value

    def convert_decimalfield_value(self, value, field):
        if value is not None:
            value = backend_utils.typecast_decimal(field.format_number(value))
        return value
        return backend_utils.typecast_decimal(field.format_number(value))

    # cx_Oracle always returns datetime.datetime objects for
    # DATE and TIMESTAMP columns, but Django wants to see a
+1 −3
Original line number Diff line number Diff line
@@ -277,9 +277,7 @@ class DatabaseOperations(BaseDatabaseOperations):
        return converters

    def convert_decimalfield_value(self, value, field):
        if value is not None:
            value = backend_utils.typecast_decimal(field.format_number(value))
        return value
        return backend_utils.typecast_decimal(field.format_number(value))

    def convert_datefield_value(self, value, field):
        if value is not None and not isinstance(value, datetime.date):
+12 −3
Original line number Diff line number Diff line
@@ -191,9 +191,18 @@ def format_number(value, max_digits, decimal_places):
    Formats a number into a string with the requisite number of digits and
    decimal places.
    """
    if value is None:
        return None
    if isinstance(value, decimal.Decimal):
        context = decimal.getcontext().copy()
        if max_digits is not None:
            context.prec = max_digits
        return "{0:f}".format(value.quantize(decimal.Decimal(".1") ** decimal_places, context=context))
        if decimal_places is not None:
            value = value.quantize(decimal.Decimal(".1") ** decimal_places, context=context)
        else:
            context.traps[decimal.Rounded] = 1
            value = context.create_decimal(value)
        return "{:f}".format(value)
    if decimal_places is not None:
        return "%.*f" % (decimal_places, value)
    return "{:f}".format(value)
+1 −1
Original line number Diff line number Diff line
@@ -255,7 +255,7 @@ class ExpressionNode(CombinableMixin):
        elif internal_type.endswith('IntegerField'):
            return int(value)
        elif internal_type == 'DecimalField':
            return backend_utils.typecast_decimal(field.format_number(value))
            return backend_utils.typecast_decimal(value)
        return value

    def get_lookup(self, lookup):
Loading