Python SDK: "No value for named parameter" when querying


When trying to execute a N1QL query using python sdk (3.0.3), using named parameters always results in “No value for named parameter $foo” even though I use the syntax suggested by the docs:

>>> clu = cast(Any, cluster).Cluster.connect(
...         f"couchbase://{cfg.COUCHBASE_HOST}:{cfg.COUCHBASE_PORT}",
...         cast(Any, cluster).ClusterOptions(
...             cast(Any, cluster).PasswordAuthenticator(cfg.COUCHBASE_USER, cfg.COUCHBASE_PASSWORD)
...         )
...     )
>>> collection = clu.bucket(bucket_name).default_collection()
>>> list(collection.query("""SELECT META().id FROM `data` WHERE META().id=$foo""", foo='ud/1/data'))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/couchbase_core/", line 529, in __iter__
    raw_rows = self.raw.fetch(self._mres)
couchbase.exceptions.CouchbaseException: <RC=0xCD[LCB_ERR_INTERNAL_SERVER_FAILURE (205)], HTTP Request failed. Examine 'objextra' for full result, Results=1, C Source=(src/pycbc_http.c,206), OBJ=ViewResult<rc=0xCD[LCB_ERR_INTERNAL_SERVER_FAILURE (205)], value={'requestID': 'd014e750-ee23-4308-98fb-4ba2f03d8d43', 'clientContextID': 'aff4f1a5ed0d87fe', 'signature': {'id': 'json'}, 'results': [], 'errors': [{'code': 5010, 'msg': 'Error evaluating span. - cause: No value for named parameter $foo.'}], 'status': 'errors', 'metrics': {'elapsedTime': '2.201548ms', 'executionTime': '2.030013ms', 'resultCount': 0, 'resultSize': 0, 'errorCount': 1}}, http_status=0, tracing_context=0, tracing_output=None>, Context={'first_error_code': 5010, 'http_response_code': 200, 'first_error_message': 'Error evaluating span. - cause: No value for named parameter $foo.', 'statement': 'SELECT META().id FROM `data` WHERE META().id=$foo', 'client_context_id': 'aff4f1a5ed0d87fe', 'query_params': '', 'http_response_body': '', 'endpoint': 'localhost:8093', 'type': 'QueryErrorContext'}, Tracing Output={":nokey:0": null}>

Is this a bug or has the query syntax changed?

Hi, for now, one runs N1QL queries from the Cluster, rather than a bucket or collection, N1QL collections support is not available prior to the pending Server 7.0.
I’m not sure if this is the cause of the issue, and the Internal Server Error and the ‘no value for named parameter $foo’ message suggest that it hasn’t been fed this correctly. But please first try running the N1QL query from the Cluster.

The syntax should be the same, although you can now use QueryOptions to specify named/positional arguments (see Sphinx/docstrings).



Thank you, querying from cluster works!

1 Like

Glad to be of service! We will soon be cleaning up some of the legacy code to remove these confusing legacy functions.