-
Notifications
You must be signed in to change notification settings - Fork 68
Closed
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
hi all! i recently hit an issue migrating an app from google.appengine.ext.ndb with a TextProperty(compressed=True), which isn't supported in google.cloud.ndb. (i'm on 0.2.0, on the Python 3 Standard runtime.)
i saw #160 and the fix in #181, particularly "we can still support compression transparently with bidirectional compatibility," and optimistically tried just removing compressed=True, but no luck. the value comes back as the raw zlib-compressed bytes, eg b'x\x9c\xed\\ks\xdb...'.
i ended up adding support myself with this custom property class:
class CompressedTextProperty(ndb.GenericProperty):
def _to_base_type(self, value):
if isinstance(value, str):
return zlib.compress(value.encode())
def _from_base_type(self, value):
if isinstance(value, bytes):
return zlib.decompress(value).decode()it'd be nice if google.cloud.ndb supported this natively!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.