/home/vagrant/.virtualenvs/cashbox/lib/python3.4/site-
packages/django/db/models/base.py in full_clean(self, exclude,
validate_unique)
1134
1135 if errors:
-> 1136 raise ValidationError(errors)
1137
1138 def clean_fields(self, exclude=None):
ValidationError: {'amount': ['Ensure that there are no more than 12 digits
in total.']}
}}}
Seems to be raised by the new Decimal validator. Decimal field's
`to_python` method creates a Decimal instance that has many decimal places
which ends up violating the `max_digits` setting on the Decimal field.
--
Ticket URL: <https://code.djangoproject.com/ticket/26189>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 0
* type: Uncategorized => Bug
* needs_tests: => 0
* needs_better_patch: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26189#comment:1>
Comment (by timgraham):
Can you provide your model and the code to reproduce the issue?
--
Ticket URL: <https://code.djangoproject.com/ticket/26189#comment:2>
* Attachment "models__piece.py" added.
Comment (by lenniezelk):
I have added the relevant model in an attachment. The affected field is
`amount`. Just creating a model instance and running `full_clean` on it
raises a `ValidationError`. Error is raised even after Here is an iPython
session I ran:
{{{#!python
In [1]: user = User.objects.get(email='jer...@gmail.com')
In [2]: account = list(user.user_accounts.first())
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
<ipython-input-2-3e7c6aabfd88> in <module>()
----> 1 account = list(user.user_accounts.first())
TypeError: 'Account' object is not iterable
In [3]: account = user.user_accounts.first()
In [4]: currency = Currency.objects.first()
In [5]: transaction = Transaction(account=account, user=user,
currency=currency, amount=34.22, date=timezone.now(),
exchange_rate=ExchangeRate.objects.first())
In [6]: transaction.full_clean()
---------------------------------------------------------------------------
ValidationError Traceback (most recent call
last)
<ipython-input-6-343b6af108cd> in <module>()
----> 1 transaction.full_clean()
/home/vagrant/.virtualenvs/cashbox/lib/python3.4/site-
packages/django/db/models/base.py in full_clean(self, exclude,
validate_unique)
1134
1135 if errors:
-> 1136 raise ValidationError(errors)
1137
1138 def clean_fields(self, exclude=None):
ValidationError: {'amount': ['Ensure that there are no more than 12 digits
in total.']}
In [7]: transaction.save()
In [8]: transaction.full_clean()
---------------------------------------------------------------------------
ValidationError Traceback (most recent call
last)
<ipython-input-8-343b6af108cd> in <module>()
----> 1 transaction.full_clean()
/home/vagrant/.virtualenvs/cashbox/lib/python3.4/site-
packages/django/db/models/base.py in full_clean(self, exclude,
validate_unique)
1134
1135 if errors:
-> 1136 raise ValidationError(errors)
1137
1138 def clean_fields(self, exclude=None):
ValidationError: {'amount_primary': ['Ensure that there are no more than
12 digits in total.'], 'amount': ['Ensure that there are no more than 12
digits in total.']}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26189#comment:3>
Comment (by timgraham):
Do you have the problem if you change the `default` and `amount` from a
`float` to `Decimal`, e.g. `amount=decimal.Decimal('34.22')`. This also
came up in #25417.
--
Ticket URL: <https://code.djangoproject.com/ticket/26189#comment:4>
Comment (by lenniezelk):
Replying to [comment:4 timgraham]:
> Do you have the problem if you change the `default` and `amount` from a
`float` to `Decimal`, e.g. `amount=decimal.Decimal('34.22')`. This also
came up in #25417.
This solves the issue. Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/26189#comment:5>
* status: new => closed
* resolution: => invalid
* component: Uncategorized => Database layer (models, ORM)
--
Ticket URL: <https://code.djangoproject.com/ticket/26189#comment:6>