| |
@@ -19,25 +19,9 @@
|
| |
|
| |
"""Database model for Bodhi updates"""
|
| |
|
| |
- from blockerbugs import db, BaseModel
|
| |
-
|
| |
- # imports required by dynamic relationships:
|
| |
- from blockerbugs.models.bug import Bug
|
| |
- from blockerbugs.models.release import Release # noqa: F401
|
| |
- from blockerbugs.models.milestone import Milestone # noqa: F401
|
| |
-
|
| |
-
|
| |
- update_fixes = db.Table(
|
| |
- 'update_fixes',
|
| |
- db.Column('bug_id', db.Integer, db.ForeignKey('bug.id')),
|
| |
- db.Column('update_id', db.Integer, db.ForeignKey('update.id'))
|
| |
- )
|
| |
-
|
| |
- update_milestones = db.Table(
|
| |
- 'update_milestones',
|
| |
- db.Column('milestone_id', db.Integer, db.ForeignKey('milestone.id')),
|
| |
- db.Column('update_id', db.Integer, db.ForeignKey('update.id'))
|
| |
- )
|
| |
+ from blockerbugs import db, BaseModel, models
|
| |
+ from blockerbugs.models import bug, milestone
|
| |
+ from blockerbugs.models import release as model_release
|
| |
|
| |
|
| |
class Update(BaseModel):
|
| |
@@ -53,16 +37,12 @@
|
| |
date_pushed_testing = db.Column(db.DateTime, nullable=True)
|
| |
date_pushed_stable = db.Column(db.DateTime, nullable=True)
|
| |
date_obsoleted = db.Column(db.DateTime, nullable=True)
|
| |
- bugs = db.relationship('Bug',
|
| |
- secondary=update_fixes,
|
| |
- backref=db.backref('updates',
|
| |
- lazy='dynamic',
|
| |
- order_by=(status.desc(), pending.desc())))
|
| |
+ bugs: list['bug.Bug'] = db.relationship(
|
| |
+ 'Bug', secondary=models.update_fixes, back_populates='updates')
|
| |
release_id = db.Column(db.Integer, db.ForeignKey('release.id'))
|
| |
- release = db.relationship('Release',
|
| |
- backref=db.backref('bugs', lazy='dynamic'))
|
| |
- milestones = db.relationship('Milestone', secondary=update_milestones,
|
| |
- backref='updates')
|
| |
+ release: 'model_release.Release' = db.relationship('Release', back_populates='updates')
|
| |
+ milestones: list['milestone.Milestone'] = db.relationship(
|
| |
+ 'Milestone', secondary=models.update_milestones, back_populates='updates')
|
| |
|
| |
def __init__(self, title, url, karma, status, bugs, release,
|
| |
milestones, stable_karma=3, date_submitted=None):
|
| |
@@ -96,15 +76,15 @@
|
| |
if updateinfo['date_pushed_stable']:
|
| |
self.date_pushed_stable = updateinfo['date_pushed_stable']
|
| |
self.pending = updateinfo['pending']
|
| |
- current_bugkeys = [(bug.bugid, bug.milestone) for bug in self.bugs]
|
| |
+ current_bugkeys = [(currentbug.bugid, currentbug.milestone) for currentbug in self.bugs]
|
| |
for bugid in updateinfo['bugs']:
|
| |
- newbugs = Bug.query.filter_by(bugid=bugid).all()
|
| |
- for bug in newbugs:
|
| |
- if not (bug.bugid, bug.milestone) in current_bugkeys:
|
| |
- self.bugs.append(bug)
|
| |
- current_bugkeys.append((bug.bugid, bug.milestone))
|
| |
- if bug.milestone and bug.milestone not in self.milestones:
|
| |
- self.milestones.append(bug.milestone)
|
| |
+ newbugs = bug.Bug.query.filter_by(bugid=bugid).all()
|
| |
+ for newbug in newbugs:
|
| |
+ if not (newbug.bugid, newbug.milestone) in current_bugkeys:
|
| |
+ self.bugs.append(newbug)
|
| |
+ current_bugkeys.append((newbug.bugid, newbug.milestone))
|
| |
+ if newbug.milestone and newbug.milestone not in self.milestones:
|
| |
+ self.milestones.append(newbug.milestone)
|
| |
|
| |
@classmethod
|
| |
def from_data(cls, updateinfo, release):
|
| |
The advantage of
back_populates=
is that it is defined on both sides of therelationship. Therefore when you look at a class, it is clear which attributes
it has, no attributes are created silently by a completely different class/
module. You can also define additional parameters like
lazy
andorder_by
on the correct side of the relationship, rather than have it reversed.
The downside of defining the relationship on both sides is that it's much easier
to stumble into a circular import. I had to rework the imports to only import
a module (instead of a particular class), and all typehints had to be defined
as strings. The association tables had to be moved into an independent module
(I decided to use
__init__.py
).@jskladan I'd very appreciate if you could look at this patch and tell me if the change seems sane to you, or if there's some gotcha in changing
backref
toback_populates
that I haven't thought of. The test suite passes and the app runs, so it seems to work exactly as before, but I'm really not sure whether there could be some other consequences. Thanks a lot.