python3 client bug+fix

Bas Bloemsaat bas at bloemsaat.com
Fri Dec 23 12:25:30 CET 2016


Hi,

Working with MonetDB I encountered a problem with queries containing
utf-8 characters. Some queries errored. I traced the error back to
mapi.py module for python3.

The problem was that encode() was applied after splicing the packet.
With encode, any utf-8 characters are expanded to multiple octets. For
a given block that exceeded MAX_PACKAGE_LENGTH this resulted in the
last few octets falling off a package. The patch below remedies this,
please apply.

Regards,
Bas Bloemsaat


--- /srv/src/monetdb/MonetDB-11.23.13/clients/python3/monetdb/mapi.py
 2016-10-07 11:00:50.000000000 +0200
+++ /home/bas/.pyenv/versions/ent_venv1/lib/python3.5/site-packages/monetdb/mapi.py
    2016-12-23 12:02:53.431357999 +0100
@@ -275,8 +275,9 @@ class Connection(object):
     def _putblock_inet(self, block):
         pos = 0
         last = 0
+        block = block.encode()
         while not last:
-            data = block[pos:pos + MAX_PACKAGE_LENGTH].encode()
+            data = block[pos:pos + MAX_PACKAGE_LENGTH]
             length = len(data)
             if length < MAX_PACKAGE_LENGTH:
                 last = 1


More information about the developers-list mailing list