]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: load bytea as bytes, not memoryview, in Python implementation
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 29 Aug 2022 01:10:27 +0000 (02:10 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 29 Aug 2022 02:06:59 +0000 (03:06 +0100)
docs/news.rst
psycopg/psycopg/types/string.py
tests/types/test_string.py

index dde142136cf9f1fb0da199ad6bae7a8ad0902361..5d16eb2e9219bdf478c3d77f222dbc521375ea90 100644 (file)
@@ -15,6 +15,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
index 9ab235c6ba068da60e7dcee1d668e78db79edf57..e7c3f1f6358a0ed0eb55cc15df8117ee98317766 100644 (file)
@@ -160,7 +160,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):
index a5f58900a92d3b4f95ca8d5deab381795617b91c..036d20626b8faba85e07ba46ac2321f63b6a093d 100644 (file)
@@ -267,8 +267,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