From 876983a4cca47be1c3ab02763bb8c9c9bd5e5f0b Mon Sep 17 00:00:00 2001 From: Jiri Kyjovsky Date: Sun, 3 Dec 2023 22:08:51 +0100 Subject: [PATCH] frontend: Add backref relationship between Package and Build ... to silence sqlalchemy warnings The Package.builds column is used only for read only purposes and needs to be ordered accordingly against Build.id. Removing viewonly=True parameter and making it read-write column will result in errors since the relationship is used only for loading objects and not for any persistence operation. Setting the relationship to read-write would result in errors since the relationship.sync_backref flag is set to True and sqlalchemy tries then to sync the Package.builds column which was never commited - thus "This session is in 'committed' state; no further SQL can be emitted within this transaction." will appear. --- frontend/coprs_frontend/coprs/models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/coprs_frontend/coprs/models.py b/frontend/coprs_frontend/coprs/models.py index 9bc99aa96..231330deb 100644 --- a/frontend/coprs_frontend/coprs/models.py +++ b/frontend/coprs_frontend/coprs/models.py @@ -876,8 +876,6 @@ class Package(db.Model, helpers.Serializer, CoprSearchRelatedData): def validate_max_builds(self, field, value): return None if value == 0 else value - builds = db.relationship("Build", order_by="Build.id") - # relations copr_id = db.Column(db.Integer, db.ForeignKey("copr.id"), index=True) copr = db.relationship("Copr", backref=db.backref("packages")) @@ -1064,7 +1062,11 @@ def __init__(self, *args, **kwargs): copr_id = db.Column(db.Integer, db.ForeignKey("copr.id"), index=True) copr = db.relationship("Copr", backref=db.backref("builds")) package_id = db.Column(db.Integer, db.ForeignKey("package.id"), index=True) - package = db.relationship("Package") + package = db.relationship( + "Package", + backref=db.backref("builds", viewonly=True, order_by="Build.id"), + foreign_keys=[package_id], + ) chroots = association_proxy("build_chroots", "mock_chroot")