Skip to content

Commit

Permalink
change get_datasets default behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dionhaefner committed Oct 25, 2018
1 parent 3bf7ac9 commit 759fa13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions terracotta/drivers/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,11 @@ def _get_datasets(self, where: Optional[Tuple[Tuple[str, str], ...]],
"""Cache-backed version of get_datasets"""
conn = self._connection

# explicitly cast to int to prevent SQL injection
page_query = f'LIMIT {int(limit)} OFFSET {int(page) * int(limit)}'
if limit is not None:
# explicitly cast parameters to int to prevent SQL injection
page_query = f'LIMIT {int(limit)} OFFSET {int(page) * int(limit)}'
else:
page_query = ''

if where is None:
rows = conn.execute(f'SELECT * FROM datasets {page_query}')
Expand All @@ -262,7 +265,7 @@ def keytuple(row: sqlite3.Row) -> Tuple[str, ...]:
@requires_connection
@convert_exceptions('Could not retrieve datasets')
def get_datasets(self, where: Mapping[str, str] = None,
page: int = 0, limit: int = 100) -> Dict[Tuple[str, ...], str]:
page: int = 0, limit: int = None) -> Dict[Tuple[str, ...], str]:
"""Retrieve keys of datasets matching given pattern"""
# make sure arguments are hashable
if where is None:
Expand Down
1 change: 1 addition & 0 deletions tests/server/test_flask_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_get_datasets(client, use_read_only_database):
rv = client.get('/datasets')
assert rv.status_code == 200
datasets = json.loads(rv.data, object_pairs_hook=OrderedDict)['datasets']
assert len(datasets) == 3
assert OrderedDict([('key1', 'val11'), ('akey', 'x'), ('key2', 'val12')]) in datasets


Expand Down

0 comments on commit 759fa13

Please sign in to comment.