From 004f469092ee5fbbb60147ae9556d87196c28031 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20=20MENAGER?= <herve.menager@pasteur.fr>
Date: Tue, 23 May 2017 15:44:17 +0200
Subject: [PATCH] add mysql convertor to avoid "bytearray" strings from mysql
 driver

Former-commit-id: 64c85ed8155a7034a145bc99b364c1f68a623def
---
 ippisite/db.sqlite3.REMOVED.git-id                 |  2 +-
 .../ippidb/management/commands/import_v1_data.py   | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/ippisite/db.sqlite3.REMOVED.git-id b/ippisite/db.sqlite3.REMOVED.git-id
index 082a3b3a..dc41e52d 100644
--- a/ippisite/db.sqlite3.REMOVED.git-id
+++ b/ippisite/db.sqlite3.REMOVED.git-id
@@ -1 +1 @@
-22fcf51cee85dcecd7c0de2fecdd0852abb2ce71
\ No newline at end of file
+2b15950995d163e68e50e2aabf1b4e9a4ff2dfeb
\ No newline at end of file
diff --git a/ippisite/ippidb/management/commands/import_v1_data.py b/ippisite/ippidb/management/commands/import_v1_data.py
index 1f6c40e7..622ede96 100644
--- a/ippisite/ippidb/management/commands/import_v1_data.py
+++ b/ippisite/ippidb/management/commands/import_v1_data.py
@@ -9,6 +9,18 @@ from ippidb.models import Bibliography, Protein, Taxonomy, MolecularFunction, \
     Domain, ProteinDomainBoundComplex, ProteinDomainPartnerComplex, Symmetry, Ppi, PpiComplex, Disease, \
     Compound, MDDRCompoundImport, MDDRActivityClass
 
+class MyConverter(mysql.connector.conversion.MySQLConverter):
+
+    def row_to_python(self, row, fields):
+        row = super(MyConverter, self).row_to_python(row, fields)
+
+        def to_unicode(col):
+            if type(col) == bytearray:
+                return col.decode('utf-8')
+            return col
+
+        return[to_unicode(col) for col in row]
+
 class Command(BaseCommand):
 
     help = "Import data from the local v1 database"
@@ -73,7 +85,7 @@ class Command(BaseCommand):
 
 
     def handle(self, *args, **options):
-        conn = mysql.connector.connect(host="localhost",user="root",password="ippidb", database="ippidb")
+        conn = mysql.connector.connect(converter_class=MyConverter, host="localhost", user="root", password="ippidb", database="ippidb")
         cursor = conn.cursor()
         if options['bibliographies']:
             cursor.execute("""SELECT * FROM biblio""")
-- 
GitLab