Skip to content

Commit

Permalink
fix(models): remove duplicated User-Workflow relationship (reanahub#234)
Browse files Browse the repository at this point in the history
Fix SQLAlchemy warning reporting conflicting relationships:

```
SAWarning: relationship 'User.workflow' will copy column user_.id_ to
column workflow.owner_id, which conflicts with relationship(s):
'User.workflows' (copies user_.id_ to workflow.owner_id),
'Workflow.user_' (copies user_.id_ to workflow.owner_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="user_,workflows"' to
the 'User.workflow' relationship. (Background on this error at:
https://sqlalche.me/e/14/qzyx)
```
  • Loading branch information
mdonadoni committed Jul 8, 2024
1 parent f341b21 commit a364bb0
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions reana_db/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2018, 2019, 2020, 2021, 2022, 2023 CERN.
# Copyright (C) 2018, 2019, 2020, 2021, 2022, 2023, 2024 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -158,7 +158,7 @@ class User(Base, Timestamp, QuotaBase):
full_name = Column(String(length=255))
username = Column(String(length=255))
tokens = relationship("UserToken", backref="user_", lazy="dynamic")
workflows = relationship("Workflow", backref="user_", lazy="dynamic")
workflows = relationship("Workflow", backref="owner", lazy="dynamic")
audit_logs = relationship("AuditLog", backref="user_")

def __init__(self, access_token=None, **kwargs):
Expand Down Expand Up @@ -486,7 +486,6 @@ class Workflow(Base, Timestamp, QuotaBase):
git_repo = Column(String(255))
git_provider = Column(String(255))
launcher_url = Column(String)
owner = relationship("User", backref="workflow")
sessions = relationship(
"InteractiveSession",
secondary="__reana.workflow_session",
Expand Down

0 comments on commit a364bb0

Please sign in to comment.