[parsing] Raise BadRQLQuery if shortcut type settings is used without any variable
Before this 'Machin 12' is transformed to 'Any 12' since it expect a 'set type
shortcut', but since the selection doesn't hold any variable, the type
information is lost and no type checking is ever done.
We can not expect to have the schema at this point, which would allow to check
if the type exists. Even if we had, we would then need dedicated structures to
hold the information that we expect entity with eid '12' to be a 'Machin'...
Thus, it seems simpler to disallow usage of this simplified form without any
selected variable.
Closes #9234282.
--- a/rql/stmts.py Wed Apr 13 11:05:54 2016 +0200
+++ b/rql/stmts.py Tue Jul 19 10:24:13 2016 +0200
@@ -551,7 +551,11 @@
assert self.selection
# Person P -> Any P where P is Person
if etype != 'Any':
- for var in self.get_selected_variables():
+ variables = list(self.get_selected_variables())
+ if not variables:
+ raise BadRQLQuery('Setting type in selection is only allowed '
+ 'when some variable is selected')
+ for var in variables:
self.add_type_restriction(var.variable, etype)
def set_distinct(self, value):
--- a/test/unittest_parser.py Wed Apr 13 11:05:54 2016 +0200
+++ b/test/unittest_parser.py Tue Jul 19 10:24:13 2016 +0200
@@ -59,6 +59,8 @@
' HAVING COUNT(X)>1 '
' WITH X,N BEING (Any X, N WHERE X name N, X is State UNION '
' Any X, N WHERE X name N, X is Transition);',
+
+ 'Machin 12',
)
# FIXME: this shoud be generated from the spec file