Skip to content

Commit

Permalink
Deprecate get_json_compatible_queryhelp in QB
Browse files Browse the repository at this point in the history
  • Loading branch information
CasperWA committed Nov 11, 2019
1 parent 3f20244 commit cc8bbc2
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions aiida/orm/querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
from inspect import isclass as inspect_isclass
import copy
import logging
import warnings
import six
from six.moves import range, zip
from six.moves import range
from sqlalchemy import and_, or_, not_, func as sa_func, select, join
from sqlalchemy.types import Integer
from sqlalchemy.orm import aliased
Expand All @@ -39,6 +40,7 @@
from aiida.common.links import LinkType
from aiida.manage.manager import get_manager
from aiida.common.exceptions import ConfigurationError
from aiida.common.warnings import AiidaDeprecationWarning

from . import authinfos
from . import comments
Expand Down Expand Up @@ -1730,15 +1732,12 @@ def get_json_compatible_queryhelp(self):
qb.all()==qb2.all()
:returns: the json-compatible queryhelp
.. deprecated:: 1.0.0
Will be removed in `v2.0.0`, use the :meth:`.queryhelp` property instead.
"""
return copy.deepcopy({
'path': self._path,
'filters': self._filters,
'project': self._projections,
'order_by': self._order_by,
'limit': self._limit,
'offset': self._offset,
})
warnings.warn('method is deprecated, use the `queryhelp` property instead', AiidaDeprecationWarning)
return self.queryhelp

@property
def queryhelp(self):
Expand All @@ -1747,11 +1746,25 @@ def queryhelp(self):
The queryhelp can be used to create a copy of the QueryBuilder instance like so::
qb = QueryBuilder(limit=3).append(StructureData, project='id').order_by({StructureData:'id'})
qb2=QueryBuilder(**qb.queryhelp)
qb2 = QueryBuilder(**qb.queryhelp)
This is a json-comptible dictionary.
In this way, the queryhelp can be stored in the database or a json-object, retrieved or shared and used later.
The following is True if no change has been made to the database::
:return: a queryhelp dictionary
# Note that such a comparison can only be True if the order of results is enforced
qb.all() == qb2.all()
:return: a json-compatible queryhelp dictionary
"""
return self.get_json_compatible_queryhelp()
return copy.deepcopy({
'path': self._path,
'filters': self._filters,
'project': self._projections,
'order_by': self._order_by,
'limit': self._limit,
'offset': self._offset,
})

def __deepcopy__(self, memo):
"""Create deep copy of QueryBuilder instance."""
Expand Down

0 comments on commit cc8bbc2

Please sign in to comment.