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 init now accepts entity_type = '' #4299

Merged
merged 2 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions aiida/orm/querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,12 +658,13 @@ def append(
# input now.
# First of all, let's make sure the specified
# the class or the type (not both)
if cls and entity_type:

if cls is not None and entity_type is not None:
raise InputValidationError(
'You cannot specify both a class ({}) and a entity_type ({})'.format(cls, entity_type)
)

if not (cls or entity_type):
if cls is None and entity_type is None:
raise InputValidationError('You need to specify at least a class or a entity_type')

# Let's check if it is a valid class or type
Expand All @@ -675,7 +676,7 @@ def append(
else:
if not inspect_isclass(cls):
raise InputValidationError("{} was passed with kw 'cls', but is not a class".format(cls))
elif entity_type:
elif entity_type is not None:
if isinstance(entity_type, (tuple, list, set)):
for sub_type in entity_type:
if not isinstance(sub_type, str):
Expand Down
8 changes: 7 additions & 1 deletion tests/orm/test_querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,16 @@ def test_queryhelp(self):
self.assertEqual(qb.count(), 1)

def test_recreate_from_queryhelp(self):
"""Test recreating a QueryBuilder from the Query Help"""
"""Test recreating a QueryBuilder from the Query Help

We test appending a Data node and a Process node for variety, as well
as a generic Node specifically because it translates to `entity_type`
as an empty string (which can potentially cause problems).
"""
import copy

qb1 = orm.QueryBuilder()
qb1.append(orm.Node)
qb1.append(orm.Data)
qb1.append(orm.CalcJobNode)

Expand Down