Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23991 closed Bug (fixed)

Oracle test failure on aggregation with max-digits

Reported by: Shai Berger Owned by: Shai Berger
Component: Database layer (models, ORM) Version: dev
Severity: Release blocker Keywords: oracle
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

On CI, reproduced locally:

ERROR: test_decimal_max_digits_has_no_effect (aggregation.tests.BaseAggregateTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/django/django/tests/aggregation/tests.py", line 702, in test_decimal_max_digits_has_no_effect
    book = Book.objects.aggregate(price_sum=Sum('price'))
  File "/home/django/django/django/db/models/manager.py", line 86, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/django/django/django/db/models/query.py", line 342, in aggregate
    return query.get_aggregation(self.db, kwargs.keys())
  File "/home/django/django/django/db/models/sql/query.py", line 422, in get_aggregation
    result = compiler.apply_converters(result, converters)
  File "/home/django/django/django/db/models/sql/compiler.py", line 696, in apply_converters
    value = converter(value, field)
  File "/home/django/django/django/db/backends/oracle/base.py", line 315, in convert_decimalfield_value
    return backend_utils.typecast_decimal(field.format_number(value))
  File "/home/django/django/django/db/models/fields/__init__.py", line 1556, in format_number
    return utils.format_number(value, self.max_digits, self.decimal_places)
  File "/home/django/django/django/db/backends/utils.py", line 201, in format_number
    value = value.quantize(decimal.Decimal(".1") ** decimal_places, context=context)
  File "/usr/lib/python2.7/decimal.py", line 2470, in quantize
    'quantize result has too many digits for current context')
  File "/usr/lib/python2.7/decimal.py", line 3874, in _raise_error
    raise error(explanation)
InvalidOperation: quantize result has too many digits for current context

I suspect the commit 267a1dcd9b7877d97917ba6222fd247da060f9b0 which fixed #23941.

Change History (3)

comment:1 by Shai Berger, 10 years ago

Version: 1.7master

comment:2 by Shai Berger <shai@…>, 10 years ago

Resolution: fixed
Status: newclosed

In 7c1f3901bcdabb1340a621e7df9b24f3acd0d6f3:

Fixed #23991 -- Apparently, Oracle doesn't need the decimal field converter

Thanks Josh Smeaton for review.

comment:3 by Josh Smeaton, 10 years ago

Just to document my findings - the sqlite backend passes a float to the format_number method which skips the digits/decimal handling logic. Oracle was passing a Decimal which caused the problem.

If 3rd party backends have issues with decimal converters, they should ensure they aren't trying to enforce max_digits on values coming from the database. The backend converter should only enforce decimal_places. The backends/utils.py already supports this:

if decimal_places is not None:  # value must be a string to get here
        return "%.*f" % (decimal_places, value)

The DecimalField's to_python and get_db_prep_save ensure that the values being saved to the database conform to the database datatype.

Note: See TracTickets for help on using tickets.
Back to Top