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

Remove get_aiida_class #2309

Merged
merged 2 commits into from Dec 7, 2018
Merged

Remove get_aiida_class #2309

merged 2 commits into from Dec 7, 2018

Conversation

muhrin
Copy link
Contributor

@muhrin muhrin commented Dec 6, 2018

Fixes #2237

This is part of the procedure that @szoupanos is leading to convert to automatically generated dummy models for the QueryBuilder

Replaced all instances with either get_backend_entity or get_orm_entity
(as appropriate).

Also changed backend group to be independent of the ORM. Because the
iterator was getting the orm class and returning that (which required it
to access up to the ORM level). Now it just returns backend entities
which are in turn converted to ORM entities by the orm.Group. This also
means you can't call len(group.nodes) because this is not allowed for
iterators but the same can be achieved with len(list(group.nodes)).

Removal of get_aiida_class from QueryBuilder and addition of
DbModel-to-BackendEntity and BackendEntity-to-OrmEntity convertors.

@muhrin muhrin requested a review from sphuber December 6, 2018 14:48
@muhrin muhrin changed the title Issue 2237 Fixes issue 2237 Dec 6, 2018
@sphuber sphuber changed the title Fixes issue 2237 Remove get_aiida_class Dec 6, 2018
Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few places with dead code, but good otherwise

aiida/orm/implementation/sqlalchemy/querybuilder.py Outdated Show resolved Hide resolved
aiida/orm/implementation/sqlalchemy/workflow.py Outdated Show resolved Hide resolved
aiida/orm/querybuilder.py Outdated Show resolved Hide resolved
aiida/orm/querybuilder.py Outdated Show resolved Hide resolved
sphuber
sphuber previously approved these changes Dec 7, 2018
aiida/orm/convert.py Outdated Show resolved Hide resolved
@@ -159,12 +162,12 @@ def __next__(self):
def next(self):
return next(self.generator)

return Iterator(self._dbmodel.dbnodes.all())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to replace this with self._dbmodel.dbnodes.all().iterator() for lazy loading also while looping with iter and next, see
see also here http://blog.etianen.com/blog/2013/06/08/django-querysets/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but we can't call count() on the iterator so I only use the iterator in the actually iteration code.

@@ -269,7 +273,7 @@ def nodes(self):
the respective AiiDA subclasses of Node, and also allows to ask for
the number of nodes in the group using len().
"""
return self._backend_entity.nodes
return map(convert.get_orm_entity, self._backend_entity.nodes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use a custom Iterator class as it is done in the Backend classes to have len pipe through the .count() method of the ORM, for efficiency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -79,7 +79,7 @@ def group_delete(group, force):
group_pk = group.pk
group_name = group.name

num_nodes = len(group.nodes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go back to len(group.nodes) once the suggested fix for len is in place, for efficiency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

giovannipizzi
giovannipizzi previously approved these changes Dec 7, 2018
szoupanos and others added 2 commits December 7, 2018 19:12
Added convertors to go from a DbModel BackendEntity and from
BackendEntity to OrmEntity.
Replaced all instances with either `get_backend_entity` or `get_orm_entity`
(as appropriate).

Also changed backend group to be independent of the ORM.  Because the
iterator was getting the ORM class and returning that, which required it
to access up to the ORM level.  Now it just returns backend entities
which are in turn converted to ORM entities by the `orm.Group`.  This also
means you can't call `len(group.nodes)` because this is not allowed for
iterators but the same can be achieved with `len(list(group.nodes))`
@sphuber sphuber merged commit a6bbe32 into provenance_redesign Dec 7, 2018
@sphuber sphuber deleted the issue_2237_rebased2 branch December 7, 2018 18:58
@coveralls
Copy link

coveralls commented Dec 8, 2018

Coverage Status

Coverage increased (+0.01%) to 68.942% when pulling 1a9c869 on issue_2237_rebased2 into 05fae57 on provenance_redesign.

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

Successfully merging this pull request may close these issues.

None yet

5 participants