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.
This commit is contained in:
Corry Haines 2014-04-24 14:59:10 -07:00
parent 03b8b1e97a
commit 82ab0cde55

View File

@ -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(")")