SQLA migration: fix RemovedIn20Warnings

This commit is contained in:
justcool393 2023-02-18 22:19:10 -06:00 committed by Ben Rog-Wilhelm
parent 449e2557d0
commit ff09ba4209
4 changed files with 11 additions and 15 deletions

View file

@ -194,12 +194,9 @@ class Comment(Base):
@property @property
@lazy @lazy
def parent(self): def parent(self):
if not self.parent_submission: return None if not self.parent_submission: return None
if self.level == 1: return self.post if self.level == 1: return self.post
else: return g.db.get(Comment, self.parent_comment_id)
else: return g.db.query(Comment).get(self.parent_comment_id)
@property @property
@lazy @lazy

View file

@ -141,13 +141,13 @@ def bulk_recompute_descendant_counts(predicate = None, db=None):
True True
) )
.group_by(parent_comments.corresponding_column(Comment.id)) .group_by(parent_comments.corresponding_column(Comment.id))
.with_only_columns([ .with_only_columns(
parent_comments.corresponding_column(Comment.id), parent_comments.corresponding_column(Comment.id),
func.coalesce( func.coalesce(
func.sum(child_comments.corresponding_column(Comment.descendant_count) + text(str(1))), func.sum(child_comments.corresponding_column(Comment.descendant_count) + text(str(1))),
text(str(0)) text(str(0))
).label('descendant_count') ).label('descendant_count')
]) )
.subquery(name='descendant_counts') .subquery(name='descendant_counts')
), ),
adapt_on_names=True adapt_on_names=True

View file

@ -25,7 +25,7 @@ def get_logged_in_user():
lo_user = session.get("lo_user") lo_user = session.get("lo_user")
if lo_user: if lo_user:
id = int(lo_user) id = int(lo_user)
v = g.db.query(User).get(id) v = g.db.get(User, id)
if v: if v:
v.client = None v.client = None
nonce = session.get("login_nonce", 0) nonce = session.get("login_nonce", 0)

View file

@ -273,12 +273,12 @@ def update_filter_status(v):
return { 'result': f'Status of {new_status} is not permitted' } return { 'result': f'Status of {new_status} is not permitted' }
if post_id: if post_id:
p = g.db.query(Submission).get(post_id) p = g.db.get(Submission, post_id)
old_status = p.filter_state old_status = p.filter_state
rows_updated = g.db.query(Submission).where(Submission.id == post_id) \ rows_updated = g.db.query(Submission).where(Submission.id == post_id) \
.update({Submission.filter_state: new_status}) .update({Submission.filter_state: new_status})
elif comment_id: elif comment_id:
c = g.db.query(Comment).get(comment_id) c = g.db.get(Comment, comment_id)
old_status = c.filter_state old_status = c.filter_state
rows_updated = g.db.query(Comment).where(Comment.id == comment_id) \ rows_updated = g.db.query(Comment).where(Comment.id == comment_id) \
.update({Comment.filter_state: new_status}) .update({Comment.filter_state: new_status})
@ -732,13 +732,12 @@ def alt_votes_get(v):
@limiter.exempt @limiter.exempt
@admin_level_required(2) @admin_level_required(2)
def admin_link_accounts(v): def admin_link_accounts(v):
u1 = get_account(request.values.get("u1", ''))
u1 = int(request.values.get("u1")) u2 = get_account(request.values.get("u2", ''))
u2 = int(request.values.get("u2"))
new_alt = Alt( new_alt = Alt(
user1=u1, user1=u1.id,
user2=u2, user2=u2.id,
is_manual=True is_manual=True
) )
@ -753,7 +752,7 @@ def admin_link_accounts(v):
g.db.add(ma) g.db.add(ma)
g.db.commit() g.db.commit()
return redirect(f"/admin/alt_votes?u1={g.db.query(User).get(u1).username}&u2={g.db.query(User).get(u2).username}") return redirect(f"/admin/alt_votes?u1={u1.id}&u2={u2.id}")
@app.get("/admin/removed/posts") @app.get("/admin/removed/posts")