cloudant / python-cloudant

A Python library for Cloudant and CouchDB
Apache License 2.0
163 stars 55 forks source link

create_query_index() failing on unpartitioned CouchDB database with message invalid_partitioned_option #468

Closed CodipherX closed 4 years ago

CodipherX commented 4 years ago

Please read these guidelines before opening an issue.

Bug Description

On trying to create query index in CouchDB 3.0.0, the request fails with an unpartitioned DB with message HTTPError: 400 Client Error: Bad Request invalid_partitioned_option

1. Steps to reproduce and the simplest code sample possible to demonstrate the issue

Execute the following code

from cloudant import couchdb
from cloudant.design_document import DesignDocument

with couchdb("admin", "admin", url="http://127.0.0.1:5984") as couchClient:
        _ = couchClient.create_database("foo")

with couchdb("admin", "admin", url="http://127.0.0.1:5984") as couchClient:
    db = couchClient["foo"]
    ddoc = DesignDocument(db, document_id="bar")
    ddoc["language"] = "query"
    ddoc.save()

with couchdb("admin", "admin", url="http://127.0.0.1:5984") as couchClient:
    db = couchClient["foo"]
    db.create_query_index(design_document_id="_design/bar",fields=["key"])

2. What you expected to happen

The index should get created

3. What actually happened

Error is thrown with message - HTTPError: 400 Client Error: Bad Request invalid_partitioned_option Requested partitioned option does not match existing value on design document _design/bar for url: http://127.0.0.1:5984/foo/_index

Environment details

4. Workaround

In the cloudant/index.py, partitioned option was set only for partitioned = True. I added an else clause for partition = False and that fixed the issue. Updating line 157-158 of cloudant/index.py

if self._partitioned:
  payload['partitioned'] = True
else:
  payload['partitioned'] = False
bessbd commented 4 years ago

Hi @CodipherX ,

Thank you for reporting this issue! According to https://docs.couchdb.org/en/stable/api/database/find.html#post--db-_index , partitioned is not optional so this seems to be a python-cloudant bug. I'll open a PR for this soon.

bessbd commented 4 years ago

Hi @CodipherX ,

I've just merged 14646b7 to master. Can you please verify that your issue is gone with that change?