Fix error: Query.join() got an unexpected keyword argument 'aliased'

This commit is contained in:
Edward Betts 2025-12-21 12:41:34 +00:00
parent a845ade3df
commit 591ffa6055

29
app.py
View file

@ -960,30 +960,33 @@ def browse_facets() -> Response:
return jsonify(params=params, facets=facets, prop_labels=find_more_props)
def get_db_items(params):
def get_db_items(params: list[tuple[str, str]]):
"""Get items for browse page based on criteria."""
q = Item.query.filter_by(is_artwork=True) # type: ignore
for pid, qid in params:
q = q.join(Triple, Item.item_id == Triple.subject_id, aliased=True).filter(
Triple.predicate_id == pid[1:], Triple.object_id == qid[1:]
t = aliased(Triple)
q = q.join(t, Item.item_id == t.subject_id).filter(
t.predicate_id == int(pid[1:]),
t.object_id == int(qid[1:]),
)
return q
def get_db_facets(params):
def get_db_facets(params: list[tuple[str, str]]):
t = aliased(Triple)
q = database.session.query(t.predicate_id, func.count().label("count"), t.object_id)
q = database.session.query(
t.predicate_id, func.count().label("count"), t.object_id
)
facet_limit = 18
for pid, qid in params:
q = q.join( # type: ignore
Triple, t.subject_id == Triple.subject_id, aliased=True
).filter(
Triple.predicate_id == pid[1:],
Triple.object_id == qid[1:],
t.predicate_id != pid[1:],
t.object_id != qid[1:],
t2 = aliased(Triple)
q = q.join(t2, t.subject_id == t2.subject_id).filter(
t2.predicate_id == int(pid[1:]),
t2.object_id == int(qid[1:]),
t.predicate_id != int(pid[1:]),
t.object_id != int(qid[1:]),
)
q = q.group_by(t.predicate_id, t.object_id)