cubicweb #2192266 UNION / ORDERBY in subqueries doesn't work with sqlite [open]

The following query:

(Any U ORDERBY L WHERE U login L) UNION (Any G ORDERBY N WHERE G is CWGroup, G name N)

throws the exception:

Traceback (most recent call last):
  File "unittest_foo.py", line 43, in test_foo
    req.execute('(Any U ORDERBY L WHERE U login L) UNION (Any G ORDERBY N WHERE G is CWGroup, G name N)')
  File "/home/adim/src/fcube/cubicweb/dbapi.py", line 485, in execute
    build_descr=build_descr, **self._txid())
  File "/home/adim/src/fcube/cubicweb/server/repository.py", line 725, in execute
    build_descr)
  File "/home/adim/src/fcube/cubicweb/devtools/__init__.py", line 748, in new_execute
    rset = base_execute(*args, **kwargs)
  File "/home/adim/src/fcube/cubicweb/server/querier.py", line 736, in execute
    results = plan.execute()
  File "/home/adim/src/fcube/cubicweb/server/querier.py", line 202, in execute
    result = step.execute()
  File "/home/adim/src/fcube/cubicweb/server/ssplanner.py", line 421, in execute
    inputmap)
  File "/home/adim/src/fcube/cubicweb/server/sources/native.py", line 542, in syntax_tree_search
    cursor = self.doexec(session, sql, args)
  File "/home/adim/src/fcube/cubicweb/server/sources/native.py", line 744, in doexec
    cursor.execute(str(query), args)
  File "/home/adim/src/fcube/logilab/database/sqlite.py", line 163, in execute
    self.__class__.__bases__[0].execute(self, final_sql , kwargs)
OperationalError: 1st ORDER BY term does not match any column in the result set

The SQL generated is:

SELECT _U.cw_eid
FROM cw_CWUser AS _U
ORDER BY _U.cw_login
UNION ALL
SELECT _G.cw_eid
FROM cw_CWGroup AS _G
ORDER BY _G.cw_name

The error is caused by the orderby variabe not being selected. However, if I try to orderby one of the selected variable:

(Any U,L ORDERBY L WHERE U login L) UNION (Any G,N ORDERBY N WHERE G is CWGroup, G name N)

The generated sql is:

SELECT _U.cw_eid, _U.cw_login
FROM cw_CWUser AS _U
ORDER BY 2
UNION ALL
SELECT _G.cw_eid, _G.cw_name
FROM cw_CWGroup AS _G
ORDER BY 2

and the error becomes:

OperationalError: ORDER BY clause should come after UNION ALL not before
prioritynormal
typebug
done in<not specified>
load1.000
load left1.000
closed by<not specified>