Placeholders in Bucket.n1ql_query does not work

Hello everyone.

The Bucket.n1ql_query code example in documentation
cb.n1ql_query('SELECT airportname, FROMtravel-sampleWHERE city=$1', "Reno")
does not work. Only
cb.n1ql_query(N1QLQuery('SELECT airportname, FROMtravel-sampleWHERE city=$1', "Reno")) works.

I just started exploring couchbase with the python SDK (v2.5.1) and ran into a problem. According to the documentation, the Bucket.n1ql_query accepts the query as string. It works fine until I start passing query with placeholders, e.g.
bucket.n1ql_query("select * from news where pub_date=$pub_d;", pub_d="2018-10-15")
which will complaint no value is found for the parameters. The placeholders work fine if I explicitly convert the query into N1QLQuery,
bucket.n1ql_query(N1QLQuery("select * from news where pub_date=$pub_d;", pub_d="2018-10-15"))

Browsing through the source code here, I realize that only the query string is passed into N1QLQuery constructor, and all the positional and keyword arguments are left out. My setup is listed as follow:

Python 3.6.6
C SDK: 2.10
Python SDK: 2.5.1

It looks like a bug to me, please correct me if this is actually behaving as expected.




Thanks for pointing this out. The ‘pure text’ n1ql_query option example is wrong. As pointed out in the same paragraph, the *args/**kwargs in this variant are passed to the N1QLRequest object, rather than the N1QLQuery object. This means a user can access these parameters without having to construct the request themselves.

The code is behaving as expected, but I’ll update the example accordingly.

Many thanks,