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

Commit 14646b7

Browse files
authored
Make create_query_index always supply partitioned (#470)
`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
1 parent dfa5a7b commit 14646b7

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# UNRELEASED
22

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

56
# 2.13.0 (2020-04-16)
67

docs/getting_started.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,12 @@ when constructing the new ``DesignDocument`` class.
284284
ddoc.add_view('myview','function(doc) { emit(doc.foo, doc.bar); }')
285285
ddoc.save()
286286
287-
Similarly, to define a partitioned Cloudant Query index you must set the
288-
``partitioned=True`` optional.
287+
288+
To define a partitioned Cloudant Query index you may set the
289+
``partitioned=True`` optional, but it is not required as the index will be
290+
partitioned by default in a partitioned database. Conversely, you must
291+
set the ``partitioned=False`` optional if you wish to create a global
292+
(non-partitioned) index in a partitioned database.
289293

290294
.. code-block:: python
291295

src/cloudant/database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ def create_query_index(
11001100
design_document_id=None,
11011101
index_name=None,
11021102
index_type='json',
1103-
partitioned=False,
1103+
partitioned=None,
11041104
**kwargs
11051105
):
11061106
"""

src/cloudant/index.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Index(object):
4747
:func:`~cloudant.database.CloudantDatabase.create_query_index`.
4848
"""
4949

50-
def __init__(self, database, design_document_id=None, name=None, partitioned=False, **kwargs):
50+
def __init__(self, database, design_document_id=None, name=None, partitioned=None, **kwargs):
5151
self._database = database
5252
self._r_session = self._database.r_session
5353
self._ddoc_id = design_document_id
@@ -154,8 +154,8 @@ def create(self):
154154
self._def_check()
155155
payload['index'] = self._def
156156

157-
if self._partitioned:
158-
payload['partitioned'] = True
157+
if self._partitioned is not None:
158+
payload['partitioned'] = bool(self._partitioned)
159159

160160
headers = {'Content-Type': 'application/json'}
161161
resp = self._r_session.post(

tests/unit/index_tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,21 @@ def test_create_a_search_index_invalid_selector_value(self):
554554
'<{} \'dict\'>'.format('type' if PY2 else 'class')
555555
)
556556

557+
def test_create_unpartitioned_query_index(self):
558+
"""
559+
Test that create_query_index works on an unpartitioned database
560+
"""
561+
ddoc = DesignDocument(self.db, document_id="unpartitioned_query_index_ddoc")
562+
ddoc["language"] = "query"
563+
ddoc.save()
564+
index = self.db.create_query_index(
565+
design_document_id="_design/unpartitioned_query_index_ddoc",
566+
fields=["key"],
567+
partitioned=False
568+
)
569+
index.create()
570+
self.assertGreater(len(self.db.get_query_indexes()), 0)
571+
557572
def test_search_index_via_query(self):
558573
"""
559574
Test that a created TEXT index will produce expected query results.

0 commit comments

Comments
 (0)