-
Notifications
You must be signed in to change notification settings - Fork 224
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 support for subclassing in Groups
to the QueryBuilder
#3903
Add support for subclassing in Groups
to the QueryBuilder
#3903
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #3903 +/- ##
===========================================
+ Coverage 78.08% 78.13% +0.04%
===========================================
Files 458 460 +2
Lines 33916 33978 +62
===========================================
+ Hits 26485 26549 +64
+ Misses 7431 7429 -2
Continue to review full report at Codecov.
|
3053e06
to
ac8470d
Compare
e0bc2e7
to
3ead824
Compare
This now allows to search for instances of `Group` and all its subclasses through the `QueryBuilder` just as implemented for the `Node` class. The subclassing is based on the `type_string` of the group instances, which in turn is defined by the entry point name. When querying for `Group` instances through the `QueryBuilder`: QueryBuilder().append(Group).all() by default subclassing is enabled and should return all instances of a subclass of `Group` as well. The same goes for subclasses of `Group` themselves. Imagine a plugin defines the following entry points: 'plugin.sub = aiida_plugin.groups:SubGroup' 'plugin.sub.a = aiida_plugin.groups:SubAGroup' 'plugin.sub.b = aiida_plugin.groups:SubBGroup' The following query: QueryBuilder().append(SubGroup).all() will return all instances of `SubGroup` but also of `SubAGroup` and `SubBGroup`. This is because their entry point names both start with the entry point name `plugin.sub` of the class that is being appended. Note that in order for all group instances to be returned when querying for the `Group` base class, a small hack had to be applied in the query builder code building the filters. Note that the entry point name of `Group` is `core` and so with the rules described above, the plugin subclasses would never be matched since their entry point names do not start with `core`. This is a problem and could be fixed by making the type string of base group instances an empty string, however, this would require using an empty string for the `Group` base class which is not allowed in Python. To still provide the desired behavior, when querying for `Group` instances the `type_string` filter is set to match anything.
3ead824
to
cac9f8b
Compare
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.
Yep that looks good to me
Fixes #3902
This now allows to search for instances of
Group
and all itssubclasses through the
QueryBuilder
just as implemented for theNode
class. The subclassing is based on the
type_string
of the groupinstances, which in turn is defined by the entry point name. When
querying for
Group
instances through theQueryBuilder
:by default subclassing is enabled and should return all instances of a
subclass of
Group
as well. The same goes for subclasses ofGroup
themselves. Imagine a plugin defines the following entry points:
The following query:
will return all instances of
SubGroup
but also ofSubAGroup
andSubBGroup
. This is because their entry point names both start with theentry point name
plugin.sub
of the class that is being appended.Note that in order for all group instances to be returned when querying
for the
Group
base class, a small hack had to be applied in the querybuilder code building the filters. Note that the entry point name of
Group
iscore
and so with the rules described above, the pluginsubclasses would never be matched since their entry point names do not
start with
core
. This is a problem and could be fixed by making thetype string of base group instances an empty string, however, this would
require using an empty string for the
Group
base class which is notallowed in Python. To still provide the desired behavior, when querying
for
Group
instances thetype_string
filter is set to match anything.