]> 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 01:10:27 +0000 (02:10 +0100)
docs/news.rst
psycopg/psycopg/types/string.py
tests/types/test_string.py

index d6a9cca1aedebd76b2bad952895516fb034cb84f..ac4d40e648fe5d33d9572dd76b6c85fc68d03e8f 100644 (file)
@@ -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
index 593055df591c248a8967316d97bb834d0f81f683..5cd0d0e072c5275c8fc4a887bbecc7d7772bb5ea 100644 (file)
@@ -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):
index 0722fcc89171c6380d367ddf9b0cd713bf726163..8499959e13f3c373651d07da76afb8794fd4f39b 100644 (file)
@@ -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