Don't try to uncompress if there's nothing to uncompress

For example, when upgrading a database from an older schema, some
fields which were meant to be decompressed would actually be None
because they have no values.
If the value is None, just return None.

Change-Id: I2802b1aabf3be5aba6b066c85b5d13abaef53ca0
This commit is contained in:
David Moreau-Simard
2017-05-02 20:53:21 -04:00
parent 01e673da02
commit a39b21570e

View File

@@ -123,7 +123,10 @@ class CompressedData(types.TypeDecorator):
return zlib.compress(json.dumps(value))
def process_result_value(self, value, dialect):
return json.loads(zlib.decompress(value))
if value is not None:
return json.loads(zlib.decompress(value))
else:
return value
def copy(self, **kwargs):
return CompressedData(self.impl.length)
@@ -143,7 +146,10 @@ class CompressedText(types.TypeDecorator):
return zlib.compress(value if value else '')
def process_result_value(self, value, dialect):
return zlib.decompress(value)
if value is not None:
return zlib.decompress(value)
else:
return value
def copy(self, **kwargs):
return CompressedText(self.impl.length)