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
Model.objects.get() raises AssertionError on multiple values
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
 
Rob Hudson  
View profile  
 More options Feb 14 2007, 9:54 am
From: "Rob Hudson" <treborhud...@gmail.com>
Date: Wed, 14 Feb 2007 06:54:26 -0800
Local: Wed, Feb 14 2007 9:54 am
Subject: Model.objects.get() raises AssertionError on multiple values
I'm wondering if maybe get should raise an error with a name like
"MultipleValueError" rather than "AssertionError" when multiple values
are found...

Yesterday I was wiring up a toggle method.  If the row is in the
database, remove it.  If it isn't in the database, add it.

I don't have the exact code in front of me but it was something like
this:

    def mytoggle(var):
        try:
            setting = Setting.objects.get(var=var)
            setting.delete()
        except DoesNotExist:
            setting.objects.create_setting(var=var).save()
        except AssertionError:
            setting.objects.filter(var=var).delete()

The check for AssertionError is a "just in case" check that somehow
the variable slipped in there twice.  But I'm wary of attaching code
to an assertion error.

I don't have a lot of Python experience so maybe that's reasonable.

Thanks,
Rob


 
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.
Gary Wilson  
View profile  
 More options Feb 16 2007, 11:43 am
From: "Gary Wilson" <gary.wil...@gmail.com>
Date: Fri, 16 Feb 2007 16:43:19 -0000
Local: Fri, Feb 16 2007 11:43 am
Subject: Re: Model.objects.get() raises AssertionError on multiple values
On Feb 14, 8:54 am, "Rob Hudson" <treborhud...@gmail.com> wrote:

> I'm wondering if maybe get should raise an error with a name like
> "MultipleValueError" rather than "AssertionError" when multiple values
> are found...

+1

 
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.
Gary Wilson  
View profile  
 More options Feb 16 2007, 3:18 pm
From: "Gary Wilson" <gary.wil...@gmail.com>
Date: Fri, 16 Feb 2007 20:18:23 -0000
Local: Fri, Feb 16 2007 3:18 pm
Subject: Re: Model.objects.get() raises AssertionError on multiple values
On Feb 14, 8:54 am, "Rob Hudson" <treborhud...@gmail.com> wrote:

> I'm wondering if maybe get should raise an error with a name like
> "MultipleValueError" rather than "AssertionError" when multiple values
> are found...

Ticket and patch created:
http://code.djangoproject.com/ticket/3511

 
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.
Rob Hudson  
View profile  
 More options Feb 16 2007, 4:09 pm
From: "Rob Hudson" <treborhud...@gmail.com>
Date: Fri, 16 Feb 2007 21:09:15 -0000
Local: Fri, Feb 16 2007 4:09 pm
Subject: Re: Model.objects.get() raises AssertionError on multiple values
Cool.  I was looking at how I'd do this but I wouldn't have known
about the add_to_class in __new__.

On Feb 16, 12:18 pm, "Gary Wilson" <gary.wil...@gmail.com> wrote:


 
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.
James Bennett  
View profile  
 More options Feb 16 2007, 4:23 pm
From: "James Bennett" <ubernost...@gmail.com>
Date: Fri, 16 Feb 2007 15:23:09 -0600
Local: Fri, Feb 16 2007 4:23 pm
Subject: Re: Model.objects.get() raises AssertionError on multiple values
On 2/16/07, Rob Hudson <treborhud...@gmail.com> wrote:

> Cool.  I was looking at how I'd do this but I wouldn't have known
> about the add_to_class in __new__.

There are some notes on the wiki about how the model system works,
useful for anyone who wants to venture in there and patch stuff:

http://code.djangoproject.com/wiki/DevModelCreation

Most things on the model class itself (including its default
exceptions) are added during the call to __new__ (including all the
default model methods, which are curried and attached).

--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."


 
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 »