Skip to content

Commit 76f9b47

Browse files
committed
[SHARE- ][Fix] Handle EmptyResultSets
1 parent dacc60d commit 76f9b47

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

share/models/fuzzycount.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
from django.db import connections
22
from django.db.models import QuerySet, Manager
3+
from django.db.models.sql.datastructures import EmptyResultSet
34

45

56
class FuzzyCountQuerySet(QuerySet):
67
def count(self):
78
cursor = connections[self.db].cursor()
8-
cursor.execute('SELECT count_estimate(%s);', (cursor.mogrify(*self.query.sql_with_params()).decode(), ))
9+
10+
try:
11+
cursor.execute('SELECT count_estimate(%s);', (cursor.mogrify(*self.query.sql_with_params()).decode(), ))
12+
except EmptyResultSet:
13+
return 0
14+
915
return int(cursor.fetchone()[0])
1016

1117
def exact_count(self):

0 commit comments

Comments
 (0)