Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
#10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal " when the decimal module has been reloaded
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Django  
View profile  
 More options Apr 27 2009, 5:54 am
From: "Django" <nore...@djangoproject.com>
Date: Mon, 27 Apr 2009 09:54:32 -0000
Local: Mon, Apr 27 2009 5:54 am
Subject: [Django] #10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal " when the decimal module has been reloaded
#10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal  " when the
decimal module has been reloaded
------------------------------------------+-------------------------------- -
 Reporter:  gagravarr                     |       Owner:  nobody    
   Status:  new                           |   Milestone:            
Component:  Database layer (models, ORM)  |     Version:  1.0      
 Keywords:                                |       Stage:  Unreviewed
Has_patch:  1                             |  
------------------------------------------+-------------------------------- -
 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

--
Ticket URL: <http://code.djangoproject.com/ticket/10933>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Django  
View profile  
 More options May 17 2009, 6:18 pm
From: "Django" <nore...@djangoproject.com>
Date: Sun, 17 May 2009 22:18:30 -0000
Local: Sun, May 17 2009 6:18 pm
Subject: Re: [Django] #10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal " when the decimal module has been reloaded
#10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal  " when the
decimal module has been reloaded
---------------------------------------------------+----------------------- -
          Reporter:  gagravarr                     |         Owner:  nobody
            Status:  new                           |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  1.0  
        Resolution:                                |      Keywords:        
             Stage:  Unreviewed                    |     Has_patch:  1    
        Needs_docs:  0                             |   Needs_tests:  0    
Needs_better_patch:  0                             |  
---------------------------------------------------+----------------------- -
Changes (by orzel):

  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 hello. I'm hit by this same problem. I'm using django trunk (mainly
 because I hoped this bug was fixed), and python 2.6.2.

--
Ticket URL: <http://code.djangoproject.com/ticket/10933#comment:1>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Django  
View profile  
 More options Sep 11 2009, 7:40 am
From: "Django" <nore...@djangoproject.com>
Date: Fri, 11 Sep 2009 11:40:25 -0000
Local: Fri, Sep 11 2009 7:40 am
Subject: Re: [Django] #10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal " when the decimal module has been reloaded
#10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal  " when the
decimal module has been reloaded
---------------------------------------------------+----------------------- -
          Reporter:  gagravarr                     |         Owner:  nobody
            Status:  new                           |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  1.0  
        Resolution:                                |      Keywords:        
             Stage:  Unreviewed                    |     Has_patch:  1    
        Needs_docs:  0                             |   Needs_tests:  0    
Needs_better_patch:  0                             |  
---------------------------------------------------+----------------------- -
Comment (by lukeplant):

 If you could reproduce the error using a reload() statement in a test
 (probably put it in regressiontests/model_fields/tests.py), that would be
 great.  After that we could decide on a fix.  The fix above is probably
 OK.  I'd really like to know why 'decimal' is being reloaded, but given
 that this is causing genuine problems for people, it's better to fix it
 than leave it until we know the root cause.

--
Ticket URL: <http://code.djangoproject.com/ticket/10933#comment:2>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Django  
View profile  
 More options Dec 22 2009, 3:33 pm
From: "Django" <nore...@djangoproject.com>
Date: Tue, 22 Dec 2009 20:33:35 -0000
Local: Tues, Dec 22 2009 3:33 pm
Subject: Re: [Django] #10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal " when the decimal module has been reloaded
#10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal  " when the
decimal module has been reloaded
---------------------------------------------------+----------------------- -
          Reporter:  gagravarr                     |         Owner:  nobody
            Status:  new                           |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  1.0  
        Resolution:                                |      Keywords:        
             Stage:  Accepted                      |     Has_patch:  1    
        Needs_docs:  0                             |   Needs_tests:  1    
Needs_better_patch:  0                             |  
---------------------------------------------------+----------------------- -
Changes (by SmileyChris):

  * needs_tests:  0 => 1
  * stage:  Unreviewed => Accepted

--
Ticket URL: <http://code.djangoproject.com/ticket/10933#comment:3>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Django  
View profile  
 More options Jan 12 2010, 10:58 am
From: "Django" <nore...@djangoproject.com>
Date: Tue, 12 Jan 2010 15:58:48 -0000
Local: Tues, Jan 12 2010 10:58 am
Subject: Re: [Django] #10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal " when the decimal module has been reloaded
#10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal  " when the
decimal module has been reloaded
---------------------------------------------------+----------------------- -
          Reporter:  gagravarr                     |         Owner:  nobody
            Status:  new                           |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  SVN  
        Resolution:                                |      Keywords:        
             Stage:  Accepted                      |     Has_patch:  1    
        Needs_docs:  0                             |   Needs_tests:  1    
Needs_better_patch:  0                             |  
---------------------------------------------------+----------------------- -
Changes (by orzel):

  * version:  1.0 => SVN

Comment:

 Hello. Just to confirm that the bug (really annoying if you have 'send
 error mail' on) in django trunk as of today, although it's really, really
 worse. If i disable the above patch (that i'm using for very long), i got
 such a mail for almost every save(). I think it happenned less often in
 may.
 I'm using apache + mod_python.
 The updated patch is :

 {{{
 --- a/django/db/models/fields/__init__.py       Tue Jan 12 16:33:40 2010
 +0100
 +++ b/django/db/models/fields/__init__.py       Tue Jan 12 16:57:48 2010
 +0100
 @@ -761,6 +761,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:

 }}}

--
Ticket URL: <http://code.djangoproject.com/ticket/10933#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Django  
View profile  
 More options Apr 29 2010, 1:11 pm
From: "Django" <nore...@djangoproject.com>
Date: Thu, 29 Apr 2010 17:11:57 -0000
Local: Thurs, Apr 29 2010 1:11 pm
Subject: Re: [Django] #10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal " when the decimal module has been reloaded
#10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal  " when the
decimal module has been reloaded
---------------------------------------------------+----------------------- -
          Reporter:  gagravarr                     |         Owner:  nobody
            Status:  new                           |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  SVN  
        Resolution:                                |      Keywords:        
             Stage:  Accepted                      |     Has_patch:  1    
        Needs_docs:  0                             |   Needs_tests:  1    
Needs_better_patch:  0                             |  
---------------------------------------------------+----------------------- -
Comment (by hotani):

 I'm having this problem with latest SVN (13053). The occasional errors are
 e-mailed to me and I am unable to reproduce. I'm going to try applying the
 patch above and seeing if that helps.

 Using apache/mod_wsgi

--
Ticket URL: <http://code.djangoproject.com/ticket/10933#comment:5>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to django-updates+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Django  
View profile  
 More options Mar 5 2011, 5:25 am
From: "Django" <nore...@djangoproject.com>
Date: Sat, 05 Mar 2011 10:25:46 -0000
Local: Sat, Mar 5 2011 5:25 am
Subject: Re: [Django] #10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal " when the decimal module has been reloaded
#10933: Avoid " TypeError: Cannot convert Decimal("0.0000") to Decimal  " when the
decimal module has been reloaded
-------------------------------------+-------------------------------------
               Reporter:  gagravarr  |        Owner:  nobody
                 Status:  new        |    Milestone:
              Component:  Database   |      Version:  SVN
  layer (models, ORM)                |     Keywords:
             Resolution:             |    Has patch:  1
           Triage Stage:  Accepted   |  Needs tests:  1
    Needs documentation:  0          |
Patch needs improvement:  0          |
-------------------------------------+-------------------------------------

Comment (by rikwade):

 I believe I am encountering this problem with my Django application. Last
 couple of lines of Django debug:

 {{{
 [...]
  File "/usr/lib/python2.5/decimal.py", line 656, in __new__
    raise TypeError("Cannot convert %r to Decimal" % value)

 TypeError: Cannot convert Decimal("10.5") to Decimal
 }}}

 I am running Django 1.2.5 with Apache 2 and WSGI. A code fix or
 documentation note with supported workaround would be appreciated.

--
Ticket URL: <http://code.djangoproject.com/ticket/10933#comment:6>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »