Skip to content

Commit

Permalink
#258 updated the checks in link update for sqlalchemy nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
lekah committed Jun 1, 2017
1 parent 14cbc81 commit d7ed92f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions aiida/orm/implementation/sqlalchemy/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sqlalchemy.orm.attributes import flag_modified

from aiida.backends.utils import get_automatic_user
from aiida.backends.sqlalchemy.models.node import DbNode, DbLink, DbPath
from aiida.backends.sqlalchemy.models.node import DbNode, DbLink
from aiida.backends.sqlalchemy.models.comment import DbComment
from aiida.backends.sqlalchemy.models.user import DbUser
from aiida.backends.sqlalchemy.models.computer import DbComputer
Expand Down Expand Up @@ -195,6 +195,7 @@ def _remove_dblink_from(self, label):

def _add_dblink_from(self, src, label=None, link_type=LinkType.UNSPECIFIED):
from aiida.backends.sqlalchemy import get_scoped_session
from aiida.orm.querybuilder import QueryBuilder
session = get_scoped_session()
if not isinstance(src, Node):
raise ValueError("src must be a Node instance")
Expand All @@ -217,10 +218,9 @@ def _add_dblink_from(self, src, label=None, link_type=LinkType.UNSPECIFIED):
# I am linking src->self; a loop would be created if a DbPath exists
# already in the TC table from self to src
if link_type is LinkType.CREATE or link_type is LinkType.INPUT:
c = session.query(literal(True)).filter(DbPath.query
.filter_by(parent_id=self.dbnode.id, child_id=src.dbnode.id)
.exists()).scalar()
if c:
if QueryBuilder().append(
Node, filters={'id':self.pk}, tag='parent').append(
Node, filters={'id':src.pk}, tag='child', descendant_of='parent').count() > 0:
raise ValueError(
"The link you are attempting to create would generate a loop")

Expand Down

0 comments on commit d7ed92f

Please sign in to comment.