Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
Make create_query_index always supply partitioned (#470)
Browse files Browse the repository at this point in the history
`create_query_index` does not always supply `partitioned` which is
always required by the service.

This commit changes that so that `partitioned` is now always
present in the `create_query_index` requests when defined.

This fixes #468
  • Loading branch information
bessbd authored May 14, 2020
1 parent dfa5a7b commit 14646b7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# UNRELEASED

- [FIXED] Set default value for `partitioned` parameter to false when creating a design document.
- [FIXED] Corrected setting of `partitioned` flag for `create_query_index` requests.

# 2.13.0 (2020-04-16)

Expand Down
8 changes: 6 additions & 2 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,12 @@ when constructing the new ``DesignDocument`` class.
ddoc.add_view('myview','function(doc) { emit(doc.foo, doc.bar); }')
ddoc.save()
Similarly, to define a partitioned Cloudant Query index you must set the
``partitioned=True`` optional.
To define a partitioned Cloudant Query index you may set the
``partitioned=True`` optional, but it is not required as the index will be
partitioned by default in a partitioned database. Conversely, you must
set the ``partitioned=False`` optional if you wish to create a global
(non-partitioned) index in a partitioned database.

.. code-block:: python
Expand Down
2 changes: 1 addition & 1 deletion src/cloudant/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ def create_query_index(
design_document_id=None,
index_name=None,
index_type='json',
partitioned=False,
partitioned=None,
**kwargs
):
"""
Expand Down
6 changes: 3 additions & 3 deletions src/cloudant/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Index(object):
:func:`~cloudant.database.CloudantDatabase.create_query_index`.
"""

def __init__(self, database, design_document_id=None, name=None, partitioned=False, **kwargs):
def __init__(self, database, design_document_id=None, name=None, partitioned=None, **kwargs):
self._database = database
self._r_session = self._database.r_session
self._ddoc_id = design_document_id
Expand Down Expand Up @@ -154,8 +154,8 @@ def create(self):
self._def_check()
payload['index'] = self._def

if self._partitioned:
payload['partitioned'] = True
if self._partitioned is not None:
payload['partitioned'] = bool(self._partitioned)

headers = {'Content-Type': 'application/json'}
resp = self._r_session.post(
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/index_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,21 @@ def test_create_a_search_index_invalid_selector_value(self):
'<{} \'dict\'>'.format('type' if PY2 else 'class')
)

def test_create_unpartitioned_query_index(self):
"""
Test that create_query_index works on an unpartitioned database
"""
ddoc = DesignDocument(self.db, document_id="unpartitioned_query_index_ddoc")
ddoc["language"] = "query"
ddoc.save()
index = self.db.create_query_index(
design_document_id="_design/unpartitioned_query_index_ddoc",
fields=["key"],
partitioned=False
)
index.create()
self.assertGreater(len(self.db.get_query_indexes()), 0)

def test_search_index_via_query(self):
"""
Test that a created TEXT index will produce expected query results.
Expand Down

0 comments on commit 14646b7

Please sign in to comment.