cloudant / python-cloudant

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

use_index param in get_query_result and get_partitioned_query_result does not support list data #473

Closed CodipherX closed 4 years ago

CodipherX commented 4 years ago

Please read these guidelines before opening an issue.

Bug Description

As per https://docs.couchdb.org/en/stable/api/database/find.html#db-find , use_index could be either as "<design_document>" or ["<design_document>", "<index_name>"] However on putting a listin the use_index param, exception is thrown

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

  1. Non-partitioned DB
    
    from cloudant import couchdb

with couchdb("admin", "admin", url="http://localhost:5984") as couchClient: selector = {'_id': {'$gt': 0}} db = couchClient["foo"] docs = db.get_query_result(selector,use_index=["ddoc","index"],raw_result=True)


2. Partitioned DB

from cloudant import couchdb

with couchdb("admin", "admin", url="http://localhost:5984") as couchClient: selector = {'_id': {'$gt': 0}} db = couchClient["bar"] docs = db.get_partitioned_query_result("pkey",selector,use_index=["index","ddoc"],raw_result=True)



### 2. What you expected to happen
The query should run successfully
### 3. What actually happened
Exception is thrown `CloudantArgumentError: Argument use_index is not an instance of expected type: <class 'str'>`
## Environment details
<!--
- Version(s) that are affected by this issue.
    > 2.0.2
- Python version
    > 3.6.2
-->
Cloudant : 2.13
Python: 3.7
bessbd commented 4 years ago

Hi @CodipherX ,

The bug seems indeed valid: https://github.com/cloudant/python-cloudant/blob/14646b7c38caeceface6e2a35f94392356886b9f/src/cloudant/_common_util.py#L123 defines use_index as STRTYPE instead of (STRTYPE, list).

Are you interested in opening a PR for this?

CodipherX commented 4 years ago

Hi @bessbd , I will open a PR soon.

Thanks and regards

ricellis commented 4 years ago

Our new cloudant-python-sdk(beta) has the array form of the API allowing for both a design document or a design document and an index to be specified in use_index.