Skip to content

Commit

Permalink
frontend: Add backref relationship between Package and Build
Browse files Browse the repository at this point in the history
... 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.
  • Loading branch information
nikromen committed Dec 3, 2023
1 parent 94f00da commit 876983a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions frontend/coprs_frontend/coprs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 876983a

Please sign in to comment.