From: Daniele Varrazzo Date: Mon, 29 Aug 2022 01:10:27 +0000 (+0100) Subject: fix: load bytea as bytes, not memoryview, in Python implementation X-Git-Tag: 3.1~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a703f7f06d81ffa708cb986a470d171f65e4ed5;p=thirdparty%2Fpsycopg.git fix: load bytea as bytes, not memoryview, in Python implementation --- diff --git a/docs/news.rst b/docs/news.rst index d6a9cca1a..ac4d40e64 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -42,6 +42,7 @@ Psycopg 3.0.17 (unreleased) - Fix segfaults on fork on some Linux systems using `ctypes` implementation (:ticket:`#300`). +- Load bytea as bytes, not memoryview, using `ctypes` implementation. Current release diff --git a/psycopg/psycopg/types/string.py b/psycopg/psycopg/types/string.py index 593055df5..5cd0d0e07 100644 --- a/psycopg/psycopg/types/string.py +++ b/psycopg/psycopg/types/string.py @@ -148,7 +148,7 @@ class ByteaLoader(Loader): self.__class__._escaping = Escaping() def load(self, data: Buffer) -> bytes: - return self._escaping.unescape_bytea(data) + return bytes(self._escaping.unescape_bytea(data)) class ByteaBinaryLoader(Loader): diff --git a/tests/types/test_string.py b/tests/types/test_string.py index 0722fcc89..8499959e1 100644 --- a/tests/types/test_string.py +++ b/tests/types/test_string.py @@ -283,8 +283,10 @@ def test_load_1byte(conn, fmt_out): cur = conn.cursor(binary=fmt_out) for i in range(0, 256): cur.execute("select set_byte('x', 0, %s)", (i,)) - assert cur.fetchone()[0] == bytes([i]) + val = cur.fetchone()[0] + assert val == bytes([i]) + assert isinstance(val, bytes) assert cur.pgresult.fformat(0) == fmt_out