-
Notifications
You must be signed in to change notification settings - Fork 192
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
add queryhelp
property to QueryBuilder
#3524
Conversation
The test I added is here: https://github.com/aiidateam/aiida-core/pull/3524/files#diff-b9a67a0878b5bdee86b7a596950bc95fR678 |
65e25ae
to
4211067
Compare
* add `queryhelp` property to QueryBuilder (currently pipes through to get_json_compatible_queryhelp) * add __deepcopy__ function to allow direct copies of QueryBuilder instances * test that QueryBuilder can be re-created from queryhelp
4211067
to
5a1f18b
Compare
aiida/orm/querybuilder.py
Outdated
""" | ||
return self.get_json_compatible_queryhelp() | ||
|
||
def __deepcopy__(self, memodict={}): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
signature should be def __deepcopy__(self, memo)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
aiida/orm/querybuilder.py
Outdated
return self.get_json_compatible_queryhelp() | ||
|
||
def __deepcopy__(self, memodict={}): | ||
qb = type(self)(**self.queryhelp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for intermediate variable assignment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had it in here as a bit of a help that what is being returned here is actually a querybuilder.
debatable though whether this is helpful - I'll get rid of it
aiida/orm/querybuilder.py
Outdated
""" | ||
return self.get_json_compatible_queryhelp() | ||
|
||
def __deepcopy__(self, memodict={}): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only __deepcopy__
implementation. Wouldn't a normal copy also not work? Since the queryhelp won't contain any references to other objects a shallow copy would also just work when implemented like this no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I chose this because the implementation of the queryhelp uses deepcopy
.
aiida-core/aiida/orm/querybuilder.py
Lines 1760 to 1767 in 5a1f18b
return copy.deepcopy({ | |
'path': self._path, | |
'filters': self._filters, | |
'project': self._projections, | |
'order_by': self._order_by, | |
'limit': self._limit, | |
'offset': self._offset, | |
}) |
And the deepcopy is actually necessary since it contains nested dictionaries:
In [1]: qb=QueryBuilder()
In [2]: qb.append(Data)
Out[2]: <aiida.orm.querybuilder.QueryBuilder at 0x11ea02208>
In [3]: qb.queryhelp
Out[3]:
{'path': [{'entity_type': 'data.Data.',
'tag': 'Data_1',
'joining_keyword': None,
'joining_value': None,
'outerjoin': False,
'edge_tag': None}],
'filters': {'Data_1': {'node_type': {'like': 'data.%'}}},
'project': {'Data_1': []},
'order_by': {},
'limit': None,
'offset': None}
Thanks @ltalirz just some minor comments |
Thanks leo |
fix #3522
queryhelp
property to QueryBuilder(currently pipes through to get_json_compatible_queryhelp)
instances
test_query.py
and merge withorm/test_querybuilder.py