From 71e68a6056287b705920739db81b2f189141e8ed Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 22 Jun 2024 14:23:22 +0100 Subject: [PATCH] Fix engine version filtering breaking `limit` Fixes #383 --- app/querybuilder.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/querybuilder.py b/app/querybuilder.py index db3f1652..8195ab8b 100644 --- a/app/querybuilder.py +++ b/app/querybuilder.py @@ -17,7 +17,7 @@ from typing import Optional, List from flask import abort, current_app, request, make_response from flask_babel import lazy_gettext, gettext, get_locale -from sqlalchemy import or_ +from sqlalchemy import or_, and_ from sqlalchemy.orm import subqueryload from sqlalchemy.sql.expression import func from sqlalchemy_searchable import search @@ -310,12 +310,9 @@ def filter_package_query(self, query): query = query.filter(or_(Package.dev_state==None, Package.dev_state != PackageDevState.DEPRECATED)) if self.version: - query = query.join(Package.releases) \ - .filter(PackageRelease.approved == True) \ - .filter(or_(PackageRelease.min_rel_id==None, - PackageRelease.min_rel_id <= self.version.id)) \ - .filter(or_(PackageRelease.max_rel_id==None, - PackageRelease.max_rel_id >= self.version.id)) + query = query.filter(Package.releases.any(and_(or_(PackageRelease.min_rel_id==None, + PackageRelease.min_rel_id <= self.version.id), or_(PackageRelease.max_rel_id==None, + PackageRelease.max_rel_id >= self.version.id)))) return query