Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryBuilder: gracefully handle errors with non-matching projection sizes #3230

Open
yakutovicha opened this issue Jul 29, 2019 · 2 comments

Comments

@yakutovicha
Copy link
Contributor

If I run a query

from datetime import timedelta
from aiida.common import timezone
now = timezone.now()

qb = QueryBuilder()
qb.append(
        CalcJobNode,
        filters={'ctime':{'>': now - timedelta(days=4)}},
        project={'id':{'func':'count'}}
    )
qb.append(
        Dict,
        filters={'attributes.energy':{'>':-5.0}},
        edge_filters={'label':{'like':'output_%'}},
        edge_project='label'
     )

I get the following error:

ProgrammingError: (psycopg2.errors.GroupingError) column "db_dblink_1.label" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...HOLD FOR SELECT count(db_dbnode_1.id) AS count_1, db_dblink_...
                                                             ^

[SQL: SELECT count(db_dbnode_1.id) AS count_1, db_dblink_1.label AS db_dblink_1_label 
FROM db_dbnode AS db_dbnode_1 JOIN db_dblink AS db_dblink_1 ON db_dblink_1.input_id = db_dbnode_1.id JOIN db_dbnode AS db_dbnode_2 ON db_dblink_1.output_id = db_dbnode_2.id 
WHERE CAST(db_dbnode_1.node_type AS VARCHAR) LIKE %(param_1)s AND db_dbnode_1.ctime > %(ctime_1)s AND CAST(db_dbnode_2.node_type AS VARCHAR) LIKE %(param_2)s AND CASE WHEN (jsonb_typeof(db_dbnode_2.attributes #> %(attributes_1)s) = %(param_3)s) THEN CAST((db_dbnode_2.attributes #>> %(attributes_1)s) AS FLOAT) > %(param_4)s ELSE %(param_5)s END AND CAST(db_dblink_1.label AS VARCHAR) LIKE %(param_6)s]
[parameters: {'param_1': 'process.calculation.calcjob.%', 'ctime_1': datetime.datetime(2019, 7, 26, 16, 33, 27, 209862, tzinfo=<UTC>), 'param_2': 'data.dict.%', 'attributes_1': '{energy}', 'param_3': 'number', 'param_4': -5.0, 'param_5': False, 'param_6': 'output_%'}]
(Background on this error at: http://sqlalche.me/e/f405)

Moreover, after such an error QueryBuilder does not work any longer (all further attempts to run a query result in the same error).

The problem comes from different size of projections. In the first case the projection is [[29]], while in the second case it is [['output_parameters'], ..., ['output_parameters']] that have different size.

It would be nice to handle properly such an error and to keep QueryBuilder operational.

@CasperWA
Copy link
Contributor

@ramirezfranciscof this may be of interest to you to know, relating to the queries for determining Nodes to delete.

@ramirezfranciscof
Copy link
Member

@CasperWA thanks for the heads up! I just checked and I only project once in each query, so I think I should be safe in regards to this issue, correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants