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
#5903 DecimalField returns default value as unicode string
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
  5 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
 
Brian Rosner  
View profile  
 More options Feb 10 2009, 7:06 pm
From: Brian Rosner <bros...@gmail.com>
Date: Tue, 10 Feb 2009 17:06:52 -0700
Local: Tues, Feb 10 2009 7:06 pm
Subject: #5903 DecimalField returns default value as unicode string
Hey all,

I recently came across the issue described in #5903 [1] earlier. There
are two distinct patches that fix the problem, but at different
levels. My inclination is to fix this issue at the model field level
and properly override get_default. My feeling is that allowing Decimal
objects to pass through force_unicode (when strings_only=True) might
cause ill-effects in other parts of Django, but I am not entirely sure
(running the test suite with the fix in force_unicode didn't cause any
failed test, but that doesn't make it right to me :). I don't see much
reason to do so. Perhaps someone can shed some light on this?

[1]: http://code.djangoproject.com/ticket/5903

--
Brian Rosner
http://oebfare.com


 
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.
Alex Gaynor  
View profile  
 More options Feb 10 2009, 7:10 pm
From: Alex Gaynor <alex.gay...@gmail.com>
Date: Tue, 10 Feb 2009 19:10:30 -0500
Local: Tues, Feb 10 2009 7:10 pm
Subject: Re: #5903 DecimalField returns default value as unicode string

It seems force_unicode is the wrong level to fix this at, and doing it in
get_default() is the right place.

Alex

--
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero


 
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.
Alex Gaynor  
View profile  
 More options Feb 10 2009, 7:16 pm
From: Alex Gaynor <alex.gay...@gmail.com>
Date: Tue, 10 Feb 2009 19:16:32 -0500
Local: Tues, Feb 10 2009 7:16 pm
Subject: Re: #5903 DecimalField returns default value as unicode string

I sent that last email off rather hastily, and didn't think about it enough,
and of course I've changed my mind :).  It seems to me this is the exact
purpose of the strings_only kwarg, for when what we want to do is make sure
a string becomes unicode, but not to mess with other objects.  Further it's
clearly how other fields(integer, date, etc.) do it, so that further the
argument that that is the correct way to handle it/use strings_only.

Alex

--
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero


 
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.
Russell Keith-Magee  
View profile  
 More options Feb 11 2009, 8:50 am
From: Russell Keith-Magee <freakboy3...@gmail.com>
Date: Wed, 11 Feb 2009 22:50:35 +0900
Local: Wed, Feb 11 2009 8:50 am
Subject: Re: #5903 DecimalField returns default value as unicode string

On Wed, Feb 11, 2009 at 9:06 AM, Brian Rosner <bros...@gmail.com> wrote:

> Hey all,

> I recently came across the issue described in #5903 [1] earlier. There
> are two distinct patches that fix the problem, but at different
> levels. My inclination is to fix this issue at the model field level
> and properly override get_default. My feeling is that allowing Decimal
> objects to pass through force_unicode (when strings_only=True) might
> cause ill-effects in other parts of Django, but I am not entirely sure
> (running the test suite with the fix in force_unicode didn't cause any
> failed test, but that doesn't make it right to me :). I don't see much
> reason to do so. Perhaps someone can shed some light on this?

Our usage of Decimals has historically been undertested, so the fact
that you get no test failures doesn't necessarily mean that changing
force_unicode won't cause problems :-)

However, in this case, I'm reasonably convinced it is the right thing
to do. The list of 'ignored' types for force_unicode is essentially
the list of data types that we use for native data representations. I
can't think of any reason that Decimals shouldn't be on that list.

If you're looking for a little more background on exactly what
force_unicode "should" do, here's a discussion from way back, when we
expanded the non-string types to include dates, times, etc:

http://groups.google.com/group/django-developers/browse_thread/thread...

My reading of that (then, as now), is that
force_unicode(strings_only=True) exists to catch string proxy objects,
not non-string objects; adding Decimal to the list of non-string
objects should be fine.

However, before you check anything in, I would suggest making sure
that we have got good test coverage for this change. In particular, I
would check that we have good Decimal tests for the following:

 * Populating initial values on forms. One of the few places that
might be relying on get_default() returning a string is in an initial
value for a form

 * Serialization, especially of an object with a decimal default value.

Yours,
Russ Magee %-)


 
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.
Malcolm Tredinnick  
View profile  
 More options Feb 11 2009, 9:53 pm
From: Malcolm Tredinnick <malc...@pointy-stick.com>
Date: Thu, 12 Feb 2009 13:53:31 +1100
Local: Wed, Feb 11 2009 9:53 pm
Subject: Re: #5903 DecimalField returns default value as unicode string
On Wed, 2009-02-11 at 22:50 +0900, Russell Keith-Magee wrote:

[...]

> However, in this case, I'm reasonably convinced it is the right thing
> to do. The list of 'ignored' types for force_unicode is essentially
> the list of data types that we use for native data representations. I
> can't think of any reason that Decimals shouldn't be on that list.

> If you're looking for a little more background on exactly what
> force_unicode "should" do, here's a discussion from way back, when we
> expanded the non-string types to include dates, times, etc:

> http://groups.google.com/group/django-developers/browse_thread/thread...

> My reading of that (then, as now), is that
> force_unicode(strings_only=True) exists to catch string proxy objects,
> not non-string objects; adding Decimal to the list of non-string
> objects should be fine.

Yes, that's the idea. I agree that allowing Decimal objects to
pass-through natively should be fine.

/me makes a note to add that summary to internal documentation in that
future when I have time to write some.

Regards,
Malcolm


 
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 »