On Fri, Mar 14, 2014 at 12:41 PM, Shai Berger <[email protected]> wrote:

> On Thursday 13 March 2014 14:34:18 Josh Smeaton wrote:
> > +1 on get_or_none. It seems to be a pattern that comes up quite a lot in
> > user code, and I know I've had use for it lots of times.
>
> Since 1.6, you should just be using first(). Compared to the
> try-get-except-DoesNotExist-return-None pattern, it is only missing the
> validation that there is, indeed, at most one objet matching the criteria.
> In
> a large majority of the cases I've seen, that validation is nice to have
> if it
> comes for free, but not worth a special effort, because it is taken care
> of by
> database constraints (in a significant part, the criteria just select by
> pk).
>

Picking the first item available (on the assumption that it is the only
item, without doing an assertion check) can lead to unexpected behaviour in
an application. On that basis, I would argue there is a valid use case
separate from `first()`


>
> I would be happy to have a validating first(),


Adding `MultipleObjectsReturned()` validation into `first()` probably isn't
going to fly for two reasons. The concept of first()/last() would break if
you could not have multiple objects, and changing would break backwards
compatibility significantly. As such I would be -1 for changing `first()`


> but the current proposition, as
> far as I understand, just overlaps existing API almost completely. I
> wouldn't
> veto it, but a strong -0 from me.
>
> Shai.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/1857272.IFIdcI8OYn%40deblack
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAHKQagG0gqOrvY%2BN_ZuU3KAC2LGZpnf3jXfR1G_Smh1BpCMXLw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to