Skip to content

Commit

Permalink
fix bug negative limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Corny committed Apr 5, 2024
1 parent f627a16 commit 9f16794
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/utils_flask_sqla/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,10 @@ def build_query_order(self, query, parameters):
def set_limit(self, q):
return q.limit(self.limit).offset(self.offset * self.limit)

def raw_query(self, process_filter=True, with_limit=True):
def raw_query(self, process_filter=True):
"""
Renvoie la requete 'brute' (sans .all)
- process_filter: application des filtres (et du sort)
- with_limit: application de la limite sur la query
"""

q = self.DB.session.query(self.view.tableDef)
Expand All @@ -255,7 +254,7 @@ def raw_query(self, process_filter=True, with_limit=True):
unordered_q = self.build_query_filters(q, self.filters)
q = self.build_query_order(unordered_q, self.filters)

if self.limit != -1 and with_limit:
if self.limit != -1:
q = self.set_limit(q)

return q
Expand All @@ -267,10 +266,10 @@ def query(self):
q = self.DB.session.query(self.view.tableDef)
nb_result_without_filter = q.count()

q = self.raw_query(process_filter=True, with_limit=False)
q = self.raw_query(process_filter=True)
total_filtered = q.count() if self.filters else nb_result_without_filter

data = self.set_limit(q).all()
data = q.all()

return data, nb_result_without_filter, total_filtered

Expand Down

0 comments on commit 9f16794

Please sign in to comment.