Skip to content

DRF 3.7.2 breaks compatibility with cDecimal #5741

Closed
@eranrund

Description

@eranrund

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

We use the cDecimal library to replace the decimal module since we require the performance benefits. Since upgrading to DRF 3.7.2 this no longer works due to #5562 and specifically https://github.com/encode/django-rest-framework/pull/5562/files#diff-af402f515db75c7c6754453cf15455d9R1130:

>>> from decimal import Decimal
>>> from cdecimal import Decimal as CDecimal
>>> Decimal('100.23').quantize(Decimal('0.00'), rounding=None)
Decimal('100.23')
>>> CDecimal('100.23').quantize(CDecimal('0.00'), rounding=None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required
>>> CDecimal('100.23').quantize(CDecimal('0.00'))
Decimal('100.23')

Passing None for rounding does not work in cDecimal. I have contacted them as well but was hoping for a workaround in DRF.

Expected behavior

Code using cDecimal continues to work.

Actual behavior

    validated_value = field.run_validation(primitive_value)
  File "env/lib/python2.7/site-packages/rest_framework/fields.py", line 523, in run_validation
    value = self.to_internal_value(data)
  File "env/lib/python2.7/site-packages/rest_framework/fields.py", line 1066, in to_internal_value
    return self.quantize(self.validate_precision(value))
  File "env/lib/python2.7/site-packages/rest_framework/fields.py", line 1131, in quantize
    context=context
TypeError: an integer is required

Thanks :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions