Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
select_related() changes type of DecimalField?
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
  3 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
 
Carsten Fuchs  
View profile  
 More options Apr 4 2011, 12:05 pm
From: Carsten Fuchs <CarstenFu...@T-Online.de>
Date: Mon, 04 Apr 2011 18:05:14 +0200
Local: Mon, Apr 4 2011 12:05 pm
Subject: select_related() changes type of DecimalField?

Dear Django list,

using Django 1.3 with Python 2.6.5 on Ubuntu 10.04 and mod_wsgi, with
Oracle database, I've just experienced a case where the use of
select_related() changes the result type of a DecimalField in a related
object from decimal.Decimal to float (which in turn breaks my application).

In detail, please consider the following models (unrelated fields
omitted for clarity):

class Code(models.Model):
     id        = models.BigIntegerField(primary_key=True)
     grenzwert = models.DecimalField(null=True, max_digits=5,
decimal_places=2, blank=True)

class Erfasst(models.Model):
     id   = models.AutoField(primary_key=True)
     code = models.ForeignKey(Code, db_column='code')

And the following shell session:

lori@keep-surfing:~/Zeiterfassung$ python manage.py shell
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
 >>> from Zeiterfassung.Lori.models import *

 >>> z = Erfasst.objects.get(id=2726498)
 >>> z.code.grenzwert
Decimal('10.00')
 >>> type(z.code.grenzwert)
<class 'decimal.Decimal'>
 >>> z.code.grenzwert > Decimal(0)
True

 >>> z = Erfasst.objects.select_related().get(id=2726498)
 >>> z.code.grenzwert
10.0
 >>> type(z.code.grenzwert)
<type 'float'>
 >>> z.code.grenzwert > Decimal(0)
False

(The last line is the one that caused/causes the problems in my app...)

In the second part of the example with select_related(), I'd have
expected that it returns type decimal.Decimal as in the first.

Is this a bug in Django?
If not, is there a better solution to the problem than using
isinstance() in every place where I have to compare DecimalField values?
(I'm still quite new to Python, and might be overlooking something
obvious...)

Python 2.7 seems to handle Decimal-float comparisons differently/better
than 2.6, and the above would probably silently work with Python 2.7,
but I currently cannot upgrade to Python 2.7.

I'd be very grateful for your advice.

Best regards,
Carsten

--
    Cafu - the open-source Game and Graphics Engine
for multiplayer, cross-platform, real-time 3D Action
           Learn more at http://www.cafu.de

  smime.p7s
6K Download

 
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.
Ian  
View profile  
 More options Apr 4 2011, 4:27 pm
From: Ian <ian.g.ke...@gmail.com>
Date: Mon, 4 Apr 2011 13:27:58 -0700 (PDT)
Local: Mon, Apr 4 2011 4:27 pm
Subject: Re: select_related() changes type of DecimalField?
On Apr 4, 12:05 pm, Carsten Fuchs <CarstenFu...@T-Online.de> wrote:

> Is this a bug in Django?
> If not, is there a better solution to the problem than using
> isinstance() in every place where I have to compare DecimalField values?
> (I'm still quite new to Python, and might be overlooking something
> obvious...)

Yes, this appears to be a bug.  If you would, please create a ticket
for it in the Django Trac so that we don't forget about it.

Thanks,
Ian


 
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.
Carsten Fuchs  
View profile  
 More options Apr 5 2011, 8:09 am
From: Carsten Fuchs <CarstenFu...@T-Online.de>
Date: Tue, 05 Apr 2011 14:09:01 +0200
Local: Tues, Apr 5 2011 8:09 am
Subject: Re: select_related() changes type of DecimalField?

Dear Ian,

Am 04.04.2011 22:27, schrieb Ian:

> Yes, this appears to be a bug.  If you would, please create a ticket
> for it in the Django Trac so that we don't forget about it.

Gladly:
http://code.djangoproject.com/ticket/15766

Best regards,
Carsten

--
    Cafu - the open-source Game and Graphics Engine
for multiplayer, cross-platform, real-time 3D Action
           Learn more at http://www.cafu.de

  smime.p7s
6K Download

 
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 »