From a364bb0a5db5bedf5c00b21e437ea8da1abd62df Mon Sep 17 00:00:00 2001 From: Marco Donadoni Date: Fri, 22 Mar 2024 17:02:37 +0100 Subject: [PATCH] fix(models): remove duplicated User-Workflow relationship (#234) 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) ``` --- reana_db/models.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/reana_db/models.py b/reana_db/models.py index f6f8d5e..36609fc 100644 --- a/reana_db/models.py +++ b/reana_db/models.py @@ -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. @@ -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): @@ -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",