Skip to content

Commit

Permalink
πŸ› FIX: sqlalchemy v2 API warning (#5177)
Browse files Browse the repository at this point in the history
This commit fixes a warning that is generated by the sqlalchemy:

SAWarning: relationship 'DbLink.input' will copy column db_dbnode.id to column db_dblink.input_id, which conflicts with relationship(s): 'DbNode.inputs_q' (copies db_dbnode.id to db_dblink.input_id), 'DbNode.outputs_q' (copies db_dbnode.id to db_dblink.input_id). If this is not the intention, consider if these relationships should be linked with back_populates, or if viewonly=True should be applied to one or more if they are read-only. For the less common case that foreign key constraints are partially overlapping, the orm.foreign() annotation can be used to isolate the columns that should be written towards.   To silence this warning, add the parameter 'overlaps="inputs_q,outputs_q"' to the 'DbLink.input' relationship.

Note a similar fix was made in aldjemy/aldjemy#199
  • Loading branch information
chrisjsewell authored Oct 15, 2021
1 parent 5acf437 commit 0b7db7b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions aiida/backends/sqlalchemy/models/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ class DbLink(Base):
Integer, ForeignKey('db_dbnode.id', ondelete='CASCADE', deferrable=True, initially='DEFERRED'), index=True
)

input = relationship('DbNode', primaryjoin='DbLink.input_id == DbNode.id')
output = relationship('DbNode', primaryjoin='DbLink.output_id == DbNode.id')
# https://docs.sqlalchemy.org/en/14/errors.html#relationship-x-will-copy-column-q-to-column-p-which-conflicts-with-relationship-s-y
input = relationship('DbNode', primaryjoin='DbLink.input_id == DbNode.id', overlaps='inputs_q,outputs_q')
output = relationship('DbNode', primaryjoin='DbLink.output_id == DbNode.id', overlaps='inputs_q,outputs_q')

label = Column(String(255), index=True, nullable=False)
type = Column(String(255), index=True)
Expand Down

0 comments on commit 0b7db7b

Please sign in to comment.