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
Backwards incompatible change by #4412 / r7977 (flatchoices)
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
 
Michael Elsdörfer  
View profile  
 More options Jul 22 2008, 7:21 am
From: Michael Elsdörfer <elsdoer...@gmail.com>
Date: Tue, 22 Jul 2008 04:21:53 -0700 (PDT)
Local: Tues, Jul 22 2008 7:21 am
Subject: Backwards incompatible change by #4412 / r7977 (flatchoices)
Previously, get_FIELD_display(), for a blank or unknown value of
FIELD, return the value unchanged, e.g. say None or an empty string.

After the change, it returns the automatically inserted blank choice
(-------). This is due to it now using field.flatchoices, which is
dynamically generated through the get_choices() method, whereas it
previously just used field.choices, which contains the unmodified
tuple the field receives through __init__.
This may also be an unwanted discrepancy between the two attributes.

Was it a conscious change? I think I did sort of prefer the old
behaviour. I'm using get_field_display in a generic scenario that
makes it hard to check the original value.

Michael


 
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 Jul 22 2008, 8:17 am
From: "Russell Keith-Magee" <freakboy3...@gmail.com>
Date: Tue, 22 Jul 2008 20:17:48 +0800
Local: Tues, Jul 22 2008 8:17 am
Subject: Re: Backwards incompatible change by #4412 / r7977 (flatchoices)
On Tue, Jul 22, 2008 at 7:21 PM, Michael  Elsdörfer

<elsdoer...@gmail.com> wrote:

> Previously, get_FIELD_display(), for a blank or unknown value of
> FIELD, return the value unchanged, e.g. say None or an empty string.

> After the change, it returns the automatically inserted blank choice
> (-------). This is due to it now using field.flatchoices, which is
> dynamically generated through the get_choices() method, whereas it
> previously just used field.choices, which contains the unmodified
> tuple the field receives through __init__.
> This may also be an unwanted discrepancy between the two attributes.
> Was it a conscious change? I think I did sort of prefer the old
> behaviour. I'm using get_field_display in a generic scenario that
> makes it hard to check the original value.

There certainly wasn't a conscious decision to change anything.
However, I'm having a little difficulty reproducing your problem.
Here's a quick test case:

class Whiz(models.Model):
    CHOICES = (
        (1,'First'),
        (0,'Other'),
    )
    c = models.IntegerField(choices=CHOICES, null=True)

__test__ = {'API_TESTS':"""

>>> w = Whiz(c=1)
>>> w.save()
>>> w.get_c_display()

u'First'

>>> w.c = 0
>>> w.save()
>>> w.get_c_display()

u'Other'

# Test an invalid data value

>>> w.c = 9
>>> w.save()
>>> w.get_c_display()

9

# Test a blank data value

>>> w.c = None
>>> w.save()
>>> print w.get_c_display()

None

"""}

This test case works fine for me both pre-7977 and post-7977. Have I
misunderstood your use case here?

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.
Michael Elsdörfer  
View profile  
 More options Jul 22 2008, 9:05 am
From: Michael Elsdörfer <elsdoer...@gmail.com>
Date: Tue, 22 Jul 2008 06:05:48 -0700 (PDT)
Local: Tues, Jul 22 2008 9:05 am
Subject: Re: Backwards incompatible change by #4412 / r7977 (flatchoices)
This should have been more obvious to me in the first place. The
problem only exists for an empty string value (the choices in my
particular case hat string keys, and the field was not nullable).
Tries this case:

>>> w = Whiz(c='')
>>> w.save()
>>> w.get_c_display()

u''

Expected:
    u''
Got:
    u'---------'

That particular case behaved differently before the change, for the
reason mentioned, i.e.:

>>> Whiz._meta.get_field('c').choices

((1, 'First'), (0, 'Other'))

>>> Whiz._meta.get_field('c').flatchoices

[('', '---------'), (1, 'First'), (0, 'Other')]

Michael


 
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 Jul 22 2008, 1:32 pm
From: Malcolm Tredinnick <malc...@pointy-stick.com>
Date: Tue, 22 Jul 2008 10:32:35 -0700
Local: Tues, Jul 22 2008 1:32 pm
Subject: Re: Backwards incompatible change by #4412 / r7977 (flatchoices)

On Tue, 2008-07-22 at 04:21 -0700, Michael Elsdörfer wrote:
> Previously, get_FIELD_display(), for a blank or unknown value of
> FIELD, return the value unchanged, e.g. say None or an empty string.

> After the change, it returns the automatically inserted blank choice
> (-------). This is due to it now using field.flatchoices, which is
> dynamically generated through the get_choices() method, whereas it
> previously just used field.choices, which contains the unmodified
> tuple the field receives through __init__.
> This may also be an unwanted discrepancy between the two attributes.

> Was it a conscious change? I think I did sort of prefer the old
> behaviour. I'm using get_field_display in a generic scenario that
> makes it hard to check the original value.

This sounds like an unintended side-effect and probably worth opening a
ticket for. That change was meant to add a new feature, not change
existing code.

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.
Michael Elsdörfer  
View profile  
 More options Jul 23 2008, 6:09 am
From: Michael Elsdörfer <elsdoer...@gmail.com>
Date: Wed, 23 Jul 2008 03:09:14 -0700 (PDT)
Local: Wed, Jul 23 2008 6:09 am
Subject: Re: Backwards incompatible change by #4412 / r7977 (flatchoices)

> This sounds like an unintended side-effect and probably worth opening a
> ticket for. That change was meant to add a new feature, not change
> existing code.

http://code.djangoproject.com/ticket/7913

 
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 »