﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
10933	"Avoid "" TypeError: Cannot convert Decimal(""0.0000"") to Decimal  "" when the decimal module has been reloaded"	gagravarr	nobody	"If for some reason the decimal module gets reloaded (seems fairly easy to trigger when using runserver, but we've seen it once or twice wiht apache + mod_python too), then calling db_obj.save() on a model with a decimal field will blow up (see http://groups.google.com/group/django-users/browse_thread/thread/7da92d7f5d6e2a53 for example)

One workaround is to have extra code in the decimal field logic in django, to detect when the value is no longer being recognised as a Decimal but is one, and port it over to the new decimal object.

{{{
--- django/db/models/fields/__init__.py (revision 9643)
+++ django/db/models/fields/__init__.py (working copy)
@@ -579,6 +579,11 @@
     def to_python(self, value):
         if value is None:
             return value
+        # Work around reload(decimal) problems
+        if not isinstance(value, decimal.Decimal) and \
+               len(str(value.__class__).split(""'"")) == 3 and \
+               str(value.__class__).split(""'"")[1] == 'decimal.Decimal':
+            return decimal.Decimal( value.to_eng_string() )
         try:
             return decimal.Decimal(value)
         except decimal.InvalidOperation:
}}}

I'm not sure if this is an ideal fix or not, but it'd be great to have this (or something like it) in django to help avoid the issue"	Bug	closed	Database layer (models, ORM)	1.3	Normal	worksforme	dceu2011	me@… Jonas Kölker MaDeuce	Accepted	1	0	1	0	0	0
