Issue: Postgres HStore column type "can't adapt type 'dict'" in peewee 3.0.18
Author: dtpxl
State: closed
Created: 2018-02-20 17:06:26

Steps to reproduce:

Install Docker and Python 3.6, run the following:

`docker run --name some-postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres`
(Alternatively, use a local postgres install matching the spec)

`pip3.6 install peewee==2.8.2`

```python
from playhouse.postgres_ext import (
    PostgresqlExtDatabase,
    Model,
    HStoreField
)

try:
    from playhouse.postgres_ext import AutoField as AutoIncField
except:
    from playhouse.postgres_ext import PrimaryKeyField as AutoIncField

db = PostgresqlExtDatabase(None)


class BaseModel(Model):
    class Meta:
        database = db


class Test(BaseModel):
    id = AutoIncField(primary_key=True)
    stuff = HStoreField()

db.init('postgres', host='localhost', user='postgres', password='mysecretpassword')

Test.create_table(fail_silently=True)

Test.create(stuff={"hello": "world"})

type(Test.select().first().stuff)
```

This successfully inserts a row into the table, and the type of the HStore column data when returned from a query is 'dict' as you'd expect.

Now run:

`pip3.6 uninstall peewee`
`pip3.6 install peewee`

And run the above code again.

The error seen on Test.create() is:

```
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 2484, in execute_sql
    cursor.execute(sql, params or ())
psycopg2.ProgrammingError: can't adapt type 'dict'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 5068, in create
    inst.save(force_insert=True)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 5191, in save
    pk_from_cursor = self.insert(**field_dict).execute()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 1447, in inner
    return method(self, database, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 1518, in execute
    return self._execute(database)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 2151, in _execute
    return super(Insert, self)._execute(database)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 1926, in _execute
    cursor = self.execute_returning(database)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 1933, in execute_returning
    cursor = database.execute(self)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/playhouse/postgres_ext.py", line 426, in execute
    cursor = self.execute_sql(sql, params, commit=commit)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 2491, in execute_sql
    self.commit()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 2287, in __exit__
    reraise(new_type, new_type(*exc_args), traceback)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 170, in reraise
    raise value.with_traceback(tb)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 2484, in execute_sql
    cursor.execute(sql, params or ())
peewee.ProgrammingError: can't adapt type 'dict'
```

When querying for an existing row, the data in the HStore column is returned as a string, e.g.:

`'"hello"=>"world"'`

Expected behaviour is that inserting or retrieving HStore data works as it did in 2.8.2, where Python dictionaries can be supplied as the value for a HStore column on insert.  Similarly, HStore data should be returned as a Python dictionary.

You need to pass `register_hstore=True` when instantiating your `PostgresqlExtDatabase`.

http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#postgres-ext-api-notes