diff --git a/models/type_decorators/ByteColumn.py b/models/type_decorators/ByteColumn.py index eba39dd..b084773 100644 --- a/models/type_decorators/ByteColumn.py +++ b/models/type_decorators/ByteColumn.py @@ -1,6 +1,9 @@ +import logging from sqlalchemy import TypeDecorator from sqlalchemy.dialects.postgresql import BYTEA +_logger = logging.getLogger(__name__) + class ByteColumn(TypeDecorator): impl = BYTEA @@ -8,10 +11,14 @@ class ByteColumn(TypeDecorator): def process_bind_param(self, value, dialect): if value is not None: - return value.encode() + return int(value).to_bytes((int(value).bit_length() + 7) // 8, 'big') return value def process_result_value(self, value, dialect): if value is not None: - return value.decode() + try: + return str(int.from_bytes(value, 'big')) + except Exception as e: + _logger.error("Error decoding value '%s': %s", value, e) + return '' return value