Uploaded image for project: 'Couchbase Python Client Library'
  1. Couchbase Python Client Library
  2. PYCBC-292

Breaks transcoder compatibility

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Fix
    • Minor
    • None
    • 2.0.3
    • library
    • Security Level: Public
    • None

    Description

      In 1.x to create a transcoder you would do the following:

      from couchbase import Couchbase, FMT_JSON, FMT_MASK, FMT_BYTES
      from couchbase.transcoder import Transcoder
       
      # We'll define our own flag.
      FMT_ZLIB = (FMT_MASK << 1) & ~FMT_MASK
      #Compress objects before storing them in CB
      class ZlibTranscoder(Transcoder):
          def encode_value(self, value, format):
              converted, flags = super(ZlibTranscoder, self).encode_value(value, format & FMT_MASK)
              if (format & FMT_ZLIB):
                  flags |= FMT_ZLIB
                  converted = zlib.compress(converted)
              return (converted, flags)
       
          def decode_value(self, value, flags):
              if (flags & FMT_ZLIB):
                  value = zlib.decompress(value)
                  flags &= FMT_MASK
              return super(ZlibTranscoder, self).decode_value(value, flags)
      

      This fails to be interpreted with this error:

      Traceback (most recent call last):
        File "/push2cb.py", line 8, in <module>
          from couchbase import Couchbase, FMT_JSON, FMT_MASK, FMT_BYTES
      ImportError: cannot import name FMT_MASK
      

      The 2.X SDK does not have `FMT_MASK`:

      https://github.com/couchbase/couchbase-python-client/blob/master/couchbase/user_constants.py#L22

      I suspect the correct constants to use now is FMT_COMMON_MASK?

      • It would be good if there is a transcoding example. I have one I can submit if you would like.
      • It would be nice to fix the compatibility breakage if we can't we should document it.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mnunberg Mark Nunberg (Inactive)
            pvarley Patrick Varley (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty