Re: [sqlalchemy] between .one() and .first()

2013-06-21 Thread Chris Withers
Indeed, this just seems like a common need. Mike, is it common enough to warrant going on the session by default? cheers, Chris On 17/06/2013 18:57, Petr Viktorin wrote: Simply handling NoResultFound should work just fine... def zero_or_one(query): try: return query.one()

Re: [sqlalchemy] between .one() and .first()

2013-06-18 Thread ian marcinkowski
From the docs: one() Return exactly one result or raise an exception. Raises sqlalchemy.orm.exc.NoResultFound if the query selects no rows. Raises sqlalchemy.orm.exc.MultipleResultsFound if multiple object identities are returned, or if multiple rows are returned for a query that does not

[sqlalchemy] between .one() and .first()

2013-06-17 Thread Chris Withers
Hi All, I seems to commonly need to do a query which should return zero or one mapped objects. .one() isn't what I want as no returned object is ok. .first() isn't what I want as if my query would return more than one object, I have the query wrong and so want an exception. Is there

Re: [sqlalchemy] between .one() and .first()

2013-06-17 Thread Wichert Akkerman
On Jun 17, 2013, at 08:58 , Chris Withers ch...@simplistix.co.uk wrote: Hi All, I seems to commonly need to do a query which should return zero or one mapped objects. .one() isn't what I want as no returned object is ok. .first() isn't what I want as if my query would return more

Re: [sqlalchemy] between .one() and .first()

2013-06-17 Thread Michael Bayer
On Jun 17, 2013, at 5:33 AM, Wichert Akkerman wich...@wiggy.net wrote: On Jun 17, 2013, at 08:58 , Chris Withers ch...@simplistix.co.uk wrote: Hi All, I seems to commonly need to do a query which should return zero or one mapped objects. .one() isn't what I want as no returned

Re: [sqlalchemy] between .one() and .first()

2013-06-17 Thread Charlie Clark
Am 17.06.2013, 08:58 Uhr, schrieb Chris Withers ch...@simplistix.co.uk: Hi All, I seems to commonly need to do a query which should return zero or one mapped objects. .one() isn't what I want as no returned object is ok. .first() isn't what I want as if my query would return more than

Re: [sqlalchemy] between .one() and .first()

2013-06-17 Thread Petr Viktorin
Simply handling NoResultFound should work just fine... def zero_or_one(query): try: return query.one() except NoResultFound: return None On Mon, Jun 17, 2013 at 6:36 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 17, 2013, at 5:33 AM, Wichert Akkerman