dominno/django-moderation — Issue #50: moderation crashes on models with DecimalField
Author: mbrochh
Created: 2011-11-24 08:10:20+00:00
State: open

I'm trying to moderate the creation of a django-shop Product model. This model has a field 'unit_price', which is a CurrencyField, which is just a fancy DecimalField (see https://github.com/divio/django-shop/blob/master/shop/util/fields.py#L6)

When I create a new product, I get the following error:

Traceback:
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
105. response = middleware_method(request, callback, callback_args, callback_kwargs)
File "/home/martin/Envs/marketto/src/ajaxmiddleware/ajaxmiddleware/middleware.py" in process_view
44. return new_callback(request, *callback_args, **callback_kwargs)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/views/generic/base.py" in view
47. return self.dispatch(request, *args, **kwargs)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/utils/decorators.py" in _wrapper
28. return bound_func(*args, **kwargs)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/utils/decorators.py" in bound_func
24. return func(self, *args2, **kwargs2)
File "/home/martin/Projects/aquasys/marketto/vivitz/vehicle_shop/views/crud.py" in dispatch
38. return super(VehicleCreateView, self).dispatch(*args, **kwargs)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/views/generic/base.py" in dispatch
68. return handler(request, *args, **kwargs)
File "/home/martin/Envs/marketto/src/ajaxmiddleware/ajaxmiddleware/views.py" in post
76. return super(HybridView, self).post(self, **kwargs)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/views/generic/edit.py" in post
172. return super(BaseCreateView, self).post(request, *args, **kwargs)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/views/generic/edit.py" in post
138. return self.form_valid(form)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/views/generic/edit.py" in form_valid
112. self.object = form.save()
File "/home/martin/Projects/aquasys/marketto/vivitz/vehicle_shop/forms.py" in save
80. return super(VehicleForm, self).save()
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/shop_simplecategories/admin.py" in save
28. product.save()
File "/home/martin/Projects/aquasys/marketto/vivitz/vehicle_shop/models.py" in save
109. super(Vehicle, self).save(*args, **kwargs)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/polymorphic/polymorphic_model.py" in save
99. return super(PolymorphicModel, self).save(*args, **kwargs)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/db/models/base.py" in save
460. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/db/models/base.py" in save_base
570. created=(not record_exists), raw=raw, using=using)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/dispatch/dispatcher.py" in send
172. response = receiver(signal=self, sender=sender, **named)
File "/home/martin/Envs/marketto/src/moderation/src/moderation/register.py" in post_save_handler
203. moderator.inform_moderator(instance)
File "/home/martin/Envs/marketto/src/moderation/src/moderation/moderator.py" in inform_moderator
135. recipient_list=MODERATORS)
File "/home/martin/Envs/marketto/src/moderation/src/moderation/moderator.py" in send
110. 'moderated_object': content_object.moderated_object,
File "/home/martin/Envs/marketto/src/moderation/src/moderation/register.py" in get_moderated_object
70. '_relation_object').get()
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/db/models/manager.py" in get
132. return self.get_query_set().get(*args, **kwargs)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/db/models/query.py" in get
344. num = len(clone)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/db/models/query.py" in __len__
82. self._result_cache = list(self.iterator())
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/db/models/query.py" in iterator
286. obj = model(*row[index_start:aggregate_start])
File "/home/martin/Envs/marketto/src/moderation/src/moderation/models.py" in __init__
68. super(ModeratedObject, self).__init__(*args, **kwargs)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/db/models/base.py" in __init__
366. signals.post_init.send(sender=self.__class__, instance=self)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/dispatch/dispatcher.py" in send
172. response = receiver(signal=self, sender=sender, **named)
File "/home/martin/Envs/marketto/src/moderation/src/moderation/fields.py" in post_init
85. self._deserialize(value))
File "/home/martin/Envs/marketto/src/moderation/src/moderation/fields.py" in _deserialize
52. for parent in obj_generator:
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/core/serializers/json.py" in Deserializer
35. for obj in PythonDeserializer(simplejson.load(stream), **options):
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/core/serializers/python.py" in Deserializer
128. data[field.name] = field.to_python(field_value)
File "/home/martin/Envs/marketto/lib/python2.6/site-packages/django/db/models/fields/__init__.py" in to_python
761. return decimal.Decimal(value)
File "/usr/lib/python2.6/decimal.py" in __new__
649. "First convert the float to a string")

Exception Type: TypeError at /shop/products/create/
Exception Value: Cannot convert float to Decimal. First convert the float to a string

I really have no clue why there is a Float involved at all... Are there known issues with DecimalFields?