[Cubicweb] Proposal: new method ResultSet.one()

Christophe de Vienne christophe at unlish.com
Fri Dec 6 23:45:28 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 am giving a second thought to this. The thing is I do not thing the
find_one_entity / find_entities "idiom" is adequate anymore if we
consider the addition of ResultSet.one().

Instead, I think we should have a "find" function, that would only
create the rql request and return the resultset. We would write :

    req.find('CWUser', login=u"cdevienne").one()



which look way cleaner to me. From there, keeping one() throwing
FindEntityError (or a children of it) raised by one() would, imo, lead
to confusion and I am not comfortable doing it.
So I would prefer to keep NoResultError and MultipleResultsError
independant from FindEntityError, ignoring the "compatibility" argument
between ResultSet.one() and RequestSessionBase.find_one_entity() because
they are not meant to be compatible.

If you think it make sens I can add a find() function (with reverse_ !),
and reimplement find_entities and find_one_entity on top of it.
To be honnest I would even suggest to deprecate, at some point, the
usage of find_entities and find_one_entity, but one() thing at a time :-).



More information about the Cubicweb mailing list