{"action":"closed","issue":{"url":"https://api.github.com/repos/coleifer/peewee/issues/1504","repository_url":"https://api.github.com/repos/coleifer/peewee","labels_url":"https://api.github.com/repos/coleifer/peewee/issues/1504/labels{/name}","comments_url":"https://api.github.com/repos/coleifer/peewee/issues/1504/comments","events_url":"https://api.github.com/repos/coleifer/peewee/issues/1504/events","html_url":"https://github.com/coleifer/peewee/issues/1504","id":298673655,"number":1504,"title":"Postgres HStore column type \"can't adapt type 'dict'\" in peewee 3.0.18","user":{"login":"dtpxl","id":600983,"avatar_url":"https://avatars2.githubusercontent.com/u/600983?v=4","gravatar_id":"","url":"https://api.github.com/users/dtpxl","html_url":"https://github.com/dtpxl","followers_url":"https://api.github.com/users/dtpxl/followers","following_url":"https://api.github.com/users/dtpxl/following{/other_user}","gists_url":"https://api.github.com/users/dtpxl/gists{/gist_id}","starred_url":"https://api.github.com/users/dtpxl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dtpxl/subscriptions","organizations_url":"https://api.github.com/users/dtpxl/orgs","repos_url":"https://api.github.com/users/dtpxl/repos","events_url":"https://api.github.com/users/dtpxl/events{/privacy}","received_events_url":"https://api.github.com/users/dtpxl/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-20T17:06:26Z","updated_at":"2018-02-20T17:48:21Z","closed_at":"2018-02-20T17:48:21Z","author_association":"NONE","body":"Steps to reproduce:\r\n\r\nInstall Docker and Python 3.6, run the following:\r\n\r\n`docker run --name some-postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres`\r\n(Alternatively, use a local postgres install matching the spec)\r\n\r\n`pip3.6 install peewee==2.8.2`\r\n\r\n```python\r\nfrom playhouse.postgres_ext import (\r\n    PostgresqlExtDatabase,\r\n    Model,\r\n    HStoreField\r\n)\r\n\r\ntry:\r\n    from playhouse.postgres_ext import AutoField as AutoIncField\r\nexcept:\r\n    from playhouse.postgres_ext import PrimaryKeyField as AutoIncField\r\n\r\ndb = PostgresqlExtDatabase(None)\r\n\r\n\r\nclass BaseModel(Model):\r\n    class Meta:\r\n        database = db\r\n\r\n\r\nclass Test(BaseModel):\r\n    id = AutoIncField(primary_key=True)\r\n    stuff = HStoreField()\r\n\r\ndb.init('postgres', host='localhost', user='postgres', password='mysecretpassword')\r\n\r\nTest.create_table(fail_silently=True)\r\n\r\nTest.create(stuff={\"hello\": \"world\"})\r\n\r\ntype(Test.select().first().stuff)\r\n```\r\n\r\nThis 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.\r\n\r\nNow run:\r\n\r\n`pip3.6 uninstall peewee`\r\n`pip3.6 install peewee`\r\n\r\nAnd run the above code again.\r\n\r\nThe error seen on Test.create() is:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py\", line 2484, in execute_sql\r\n    cursor.execute(sql, params or ())\r\npsycopg2.ProgrammingError: can't adapt type 'dict'\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py\", line 5068, in create\r\n    inst.save(force_insert=True)\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py\", line 5191, in save\r\n    pk_from_cursor = self.insert(**field_dict).execute()\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py\", line 1447, in inner\r\n    return method(self, database, *args, **kwargs)\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py\", line 1518, in execute\r\n    return self._execute(database)\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py\", line 2151, in _execute\r\n    return super(Insert, self)._execute(database)\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py\", line 1926, in _execute\r\n    cursor = self.execute_returning(database)\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py\", line 1933, in execute_returning\r\n    cursor = database.execute(self)\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/playhouse/postgres_ext.py\", line 426, in execute\r\n    cursor = self.execute_sql(sql, params, commit=commit)\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py\", line 2491, in execute_sql\r\n    self.commit()\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py\", line 2287, in __exit__\r\n    reraise(new_type, new_type(*exc_args), traceback)\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py\", line 170, in reraise\r\n    raise value.with_traceback(tb)\r\n  File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py\", line 2484, in execute_sql\r\n    cursor.execute(sql, params or ())\r\npeewee.ProgrammingError: can't adapt type 'dict'\r\n```\r\n\r\nWhen querying for an existing row, the data in the HStore column is returned as a string, e.g.:\r\n\r\n`'\"hello\"=>\"world\"'`\r\n\r\nExpected 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."}}
{"actor":{"display_login":"coleifer"}}