Skip to content

bug: ClusterOptions(serializer=...) is not applied to transactional query rows #68

Open

Description

@alex-raw

Summary

Rows from ctx.query(...) inside a transaction are not decoded with the serializer set in ClusterOptions, although the same serializer decodes cluster.query(...) rows and, within the transaction, ctx.get(...) content. In the script below, one document reads as Decimal('0.1') through ctx.get and as 0.1 (a float) through ctx.query, with no serializer call for the query and no warning.

ClusterOptions documents serializer as the "Global serializer to translate JSON to Python objects" (options.py), and commit ae90034a for PYCBC-1294 states: "The transactions spec actually only supports using the serializer that the Cluster uses." Java 3.13.0 decodes transactional query rows with the cluster environment's JsonSerializer (Cluster.java#L729, TransactionAttemptContext.java#L386), and PYCBC-1965 describes the same kind of gap on search and view rows: "Query and analytics apply the same option to every row, so a caller with a custom serializer gets it on two streaming services and silently not on the other two."

At tag 4.6.4 and on master (97f4504f), TransactionQueryResults.__init__ decodes the whole response with DefaultJsonSerializer().deserialize(res) (transaction_query_results.py#L51); acouchbase does the same, and patch set 6 of change 256359 (PYCBC-2007, 4.7.0) keeps that call. PYCBC-1604 asked for a serializer on TransactionQueryOptions in the FIT performer and was closed because the performer does not support transactions.

Reproduction

"""Rows of a transactional query bypass ClusterOptions(serializer=...).

Usage: python txn_query_serializer.py <connection string> <bucket> <username> <password>
"""
import json
import sys
from decimal import Decimal
from importlib.metadata import version

from couchbase.auth import PasswordAuthenticator
from couchbase.cluster import Cluster
from couchbase.options import ClusterOptions
from couchbase.serializer import Serializer


class DecimalSerializer(Serializer):
    calls = 0

    def serialize(self, value):
        return json.dumps(value).encode()

    def deserialize(self, value):
        DecimalSerializer.calls += 1
        return json.loads(value, parse_float=Decimal)


connstr, bucket, username, password = sys.argv[1:]
cluster = Cluster(connstr, ClusterOptions(PasswordAuthenticator(username, password),
                                          serializer=DecimalSerializer()))
collection = cluster.bucket(bucket).default_collection()
collection.upsert("doc", {"balance": 0.1})
statement = f"SELECT d.balance FROM `{bucket}` AS d USE KEYS 'doc'"
print(f"couchbase {version('couchbase')}, Python {sys.version.split()[0]}")
print("cluster.query :", list(cluster.query(statement).rows()))


def read_by_key_and_by_query(ctx):
    print("ctx.get       :", ctx.get(collection, "doc").content_as[dict])
    calls = DecimalSerializer.calls
    print("ctx.query     :", ctx.query(statement).rows())
    print("serializer calls during ctx.query:", DecimalSerializer.calls - calls)


cluster.transactions.run(read_by_key_and_by_query)

Expected

ctx.query returns [{'balance': Decimal('0.1')}], as cluster.query does, and the serializer is called for it.

Observed

couchbase 4.6.4, Python 3.14.8
cluster.query : [{'balance': Decimal('0.1')}]
ctx.get       : {'balance': Decimal('0.1')}
ctx.query     : [{'balance': 0.1}]
serializer calls during ctx.query: 0

Environment

  • couchbase 4.6.4
  • Python 3.14.8 (the same output on 3.13.12), Couchbase Server 8.0.0-3777-enterprise, Linux x86_64

Activity

  1. thejcfactor commented on Nov 4, 2026

    @thejcfactor
    Contributor

    Hi @alex-raw -- Thanks for raising this issue. Let me see if we can sneak it into the 4.7.0 release. If not, we will get it in the next release round. I will follow back up w/ a PYCBC shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions