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

Denis Laxalde denis.laxalde at logilab.fr
Mon Dec 9 09:52:07 CET 2013

Christophe de Vienne a écrit :
> 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()
> or
>      req.find('CWGroup').entities()
> 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 :-).

Not a bad idea, IMHO.

More information about the Cubicweb mailing list