Skip to content

Commit

Permalink
Inefficent Queries (get/filter) Don't Return Results In Some Cases
Browse files Browse the repository at this point in the history
Nasty bug here where for inefficient queries the limit on the query wasn't being reset. Somewhere in the get/filter django sets a limit to 21 (I think this is MAX_GET_RESULTS +1; use grep to find if curious). When there were more than 21 results in the query set there was a good chance that the result that matches the provided filter would not be in the result set.
  • Loading branch information
Seth Denner committed Oct 29, 2015
1 parent 82f314c commit 87fe727
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python setup.py sdist && cp dist/djangocassandra-0.0.4.tar.gz ../knotis.com/web/dist/ && docker exec knotiscom_web_1 /srv/knotis/venv/bin/pip install --upgrade --no-deps /srv/knotis/web/dist/djangocassandra-0.0.4.tar.gz
5 changes: 3 additions & 2 deletions djangocassandra/db/backends/cassandra/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def __init__(
self.columns.append(f)

self.where = None
self.limit = 1000000 # TODO: Make this a config setting
self.default_limit = 1000000 # TODO: Make this a config setting
self.limit = self.default_limit
self.timeout = None # TODO: Make this a config setting
self.cache = None
self.allows_inefficient = (
Expand Down Expand Up @@ -230,7 +231,7 @@ def get_row_range(self, range_predicates):
return self._get_rows_by_indexed_column(range_predicates)

def get_all_rows(self):
return self.cql_query.all()
return self.cql_query.limit(self.default_limit).all()

def _get_query_results(self):
if None is self.cache:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='djangocassandra',
version='0.2.2',
version='0.2.3',
description='Cassandra support for the Django web framework',
long_description=(
'The Cassandra database backend for Django has been '
Expand Down
12 changes: 12 additions & 0 deletions tests/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ def setUp(self):
def tearDown(self):
destroy_db(self.connection)

def test_filter_on_unindexed_column(self):
field_3_filter = SimpleTestModel.objects.filter(field_3='raw')

expected_count = 0
for _, o in self.cached_rows.iteritems():
if o.field_3 == 'raw':
expected_count += 1

self.assertEqual(expected_count, len(field_3_filter))
for o in field_3_filter:
self.assertTrue(o.pk in self.cached_rows.keys())

def test_query_all(self):
all_rows = list(SimpleTestModel.objects.all())

Expand Down

0 comments on commit 87fe727

Please sign in to comment.