[Cubicweb] Proposal: new method ResultSet.one()
Christophe de Vienne
cdevienne at gmail.com
Fri Dec 6 11:00:32 CET 2013
Le 06/12/2013 10:51, Denis Laxalde a écrit :
> Sylvain Thénault a écrit :
>> IMO rset.one() or rset.one_entity() with desired sanity check would
>> be useful.
> Agreed. I, for one, use req.find_one_entity() quite often. Having the
> counterpart on result set seems natural to me.
I therefore propose a patch :
Things to be discussed about it :
- the function name. I used one() for being short, easy to remember, and
(imho) non ambiguous. But I would understand if some preferred
one_entity() for name consistency.
- the raised exceptions : I added 2 new exceptions : NoResultError and
MultipleResultsError. This is directly taken from SQLAlchemy, and may
not suit your coding rules.
More information about the Cubicweb