[Cubicweb] An rql bug ?
sylvain.thenault at logilab.fr
Wed Feb 11 10:34:47 CET 2015
On 11 février 09:48, Alain Leufroy wrote:
> aurélien campéas <aurelien.campeas at gmail.com> writes:
> >> On 04 février 16:00, aurélien campéas wrote:
> >> > It does the trick ! Thank you very much :)
> >> that's because OR doesn't work like most people would expect. Every
> >> variable in
> >> a rql statement (eg beside subquery and union query) has a single
> >> "identity",
> >> even those in EXISTS scope.
> > Yes, and I know that quite well, but I have some difficulties "computing"
> > the
> > behaviour of the expression with a shared variable (in my head).
> > For instance, it is not intuitive that the combination of these clauses
> > yields what I saw.
> I had troubles explaining constraints with that issue when the subject
> of a relation has more than one entity type. For example:
> class run(RelationDefinition):
> subject = ('Project', 'System')
> object = 'Subprocess'
> class in_project(RelationDefinition):
> subject = 'Subject'
> object = 'System'
> class can_run(RelationDefinition):
> subject = 'CWUser'
> object = 'Project'
> And I would like to write the following permission rule on `run`:
> RRQLExpression('EXISTS(U can_run O) OR EXISTS(U can_run X, O in_project X)')
> Adding this permission rule fails with a "type inconsistancy"
> exception from rql.
> Looking into the rql code, it seems that the type checker consideres the
> OR like an AND, that is the types in the first part 'and' the types of
> variables in the second part must be similar.
That's because of the way the type resolver work. It uses Constraint Programming
for computing possible types for variables, and every relation 'X rel Y' add
some constraints to the CSP, depending on the schema, without considering OR nor
In your case, you should use 2 separated expression, those leading to type
resolver error should be discarded at run time.
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure: http://www.logilab.fr/services
CubicWeb, the semantic web framework: http://www.cubicweb.org
More information about the Cubicweb