From 82ab0cde55c40931fee1d5ce148f87af8779a086 Mon Sep 17 00:00:00 2001 From: Corry Haines Date: Thu, 24 Apr 2014 14:59:10 -0700 Subject: [PATCH] Modify hstore adaptor to only produce strings The prior implementation would adapt the types, and the following would happen: input: {'foo': True, 'bar': "baz"} output: hstore(ARRAY['foo', 'bar'], ARRAY[true, 'baz']) The output value of foo is a boolean type, which is not acceptable in an hstore (at least not with this creation method). Anyways, coercing everything to a string solves the issue. I am using the unicode function to make the tests happy. --- lib/extras.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extras.py b/lib/extras.py index b21e223d..c108745c 100644 --- a/lib/extras.py +++ b/lib/extras.py @@ -644,7 +644,7 @@ class HstoreAdapter(object): k = _ext.adapt(self.wrapped.keys()) k.prepare(self.conn) - v = _ext.adapt(self.wrapped.values()) + v = _ext.adapt([unicode(x) if x is not None else None for x in self.wrapped.values()]) v.prepare(self.conn) return b("hstore(") + k.getquoted() + b(", ") + v.getquoted() + b(")")