cloudant / python-cloudant

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

Cannot get db_info from a document with unicode in the id #401

Closed jcounts closed 6 years ago

jcounts commented 6 years ago

Please read these guidelines before opening an issue.

Bug Description

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

The following (where user and password are assumed to be correctly defined):

with cloudant(
    user,
    password,
    account='someuseraccount'
) as client:
    db = client['somedatabase']
    ddoc = db[u'\u05de\u05d2\u05d9\u05e2(\u05d4)']
    pprint.pprint(ddoc.info())

2. What you expected to happen

Results of ddoc.info() should be returned.

3. What actually happened

KeyError: u'\u05de' is raised.

Environment details

smithsz commented 6 years ago

Can you please try passing the Python string version instead? i.e.

ddoc = db[u'_design/\u05de\u05d2\u05d9\u05e2(\u05d4)'.encode('utf-8')]

Let me know how you get on.

jcounts commented 6 years ago

Using encode works.

We are planning on moving to python3 soon, I recall reading that there are some issues converting encode/decode from 2 to 3. Do you have any advice on a way to try and future proof this?

smithsz commented 6 years ago

I'm afraid not. You'll need to adapt your code when moving to Py3 since calling encode on a str will give you the new byte type, not a str.

Please reopen if you have any further questions.