Skip to content

Commit

Permalink
Revert db.session.query (#1846)
Browse files Browse the repository at this point in the history
  • Loading branch information
seeker25 authored Dec 3, 2024
1 parent 81f6f88 commit f0b449a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pay-api/src/pay_api/models/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ def search_purchase_history( # noqa:E501; pylint:disable=too-many-arguments, to
if not return_all:
count_future = executor.submit(cls.get_count, auth_account_id, search_filter)
sub_query = cls.generate_subquery(auth_account_id, search_filter, limit, page)
# Need to do it this way otherwise doesn't know how to join for the subquery for some reason.
invoice_ids = {item for t in sub_query.all() for item in t}
query = query.filter(Invoice.id.in_(invoice_ids)).order_by(Invoice.id.desc())
query = query.filter(Invoice.id.in_(sub_query.subquery().select())).order_by(Invoice.id.desc())
result_future = executor.submit(db.session.query(Invoice).from_statement(query).all)
count = count_future.result()
result = result_future.result()
Expand Down Expand Up @@ -518,7 +516,7 @@ def generate_subquery(cls, auth_account_id, search_filter, limit, page):
subquery = subquery.limit(limit)
if limit and page:
subquery = subquery.offset((page - 1) * limit)
return db.session.query(subquery.subquery())
return subquery


class PaymentSchema(BaseSchema): # pylint: disable=too-many-ancestors
Expand Down

0 comments on commit f0b449a

Please sign in to comment.