{"action":"created","issue":{"url":"https://api.github.com/repos/coleifer/peewee/issues/902","repository_url":"https://api.github.com/repos/coleifer/peewee","labels_url":"https://api.github.com/repos/coleifer/peewee/issues/902/labels{/name}","comments_url":"https://api.github.com/repos/coleifer/peewee/issues/902/comments","events_url":"https://api.github.com/repos/coleifer/peewee/issues/902/events","html_url":"https://github.com/coleifer/peewee/issues/902","id":144563715,"number":902,"title":"TypeError: unhashable type: 'list' when using playhouse.dataset with Postgres","user":{"login":"mivade","id":2805515,"avatar_url":"https://avatars.githubusercontent.com/u/2805515?v=3","gravatar_id":"","url":"https://api.github.com/users/mivade","html_url":"https://github.com/mivade","followers_url":"https://api.github.com/users/mivade/followers","following_url":"https://api.github.com/users/mivade/following{/other_user}","gists_url":"https://api.github.com/users/mivade/gists{/gist_id}","starred_url":"https://api.github.com/users/mivade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mivade/subscriptions","organizations_url":"https://api.github.com/users/mivade/orgs","repos_url":"https://api.github.com/users/mivade/repos","events_url":"https://api.github.com/users/mivade/events{/privacy}","received_events_url":"https://api.github.com/users/mivade/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-03-30T11:44:16Z","updated_at":"2016-03-31T07:46:02Z","closed_at":null,"body":"I'm attempting to use the `playhouse.dataset` to lazily write data to a Postgres database. The data looks like this:\r\n\r\n```python\r\n{'beat1_lb_mon': 10.0,\r\n 'beat1_lb_status': 0,\r\n 'beat1_signal': 0.750122,\r\n 'beat1_signalaux': 0.377197,\r\n 'beat1_waveplate': 32830.0,\r\n 'beat2_lb_mon': 10.0,\r\n 'beat2_lb_status': 0,\r\n 'beat2_signal': 0.388794,\r\n 'beat2_signalaux': 0.238648,\r\n 'counter0_freq': 20000375.73899996,\r\n 'counter0_freqref': 5000000.0,\r\n 'counter1_freq': 20000000.09199998,\r\n 'counter1_freqref': 20000000.0,\r\n 'counter2_freq': 59999999.972,\r\n 'counter2_signal': 0.7489009999999999,\r\n 'counter3_freq': 19548567.59900001,\r\n 'counter3_signal': 0.377808,\r\n 'counter_channels': 4,\r\n 'counter_gatetime': 1.0,\r\n 'cw1_freq': -80000000.06399998,\r\n 'cw2_freq': -39548567.69099999,\r\n 'laser_mldet_ac': 1168.0,\r\n 'laser_mldet_dc': 321.0,\r\n 'lb1_mon': 6.230468,\r\n 'lb1_status': 2,\r\n 'lb2_mon': 0.546822,\r\n 'lb2_status': 2,\r\n 'lb3_mon': 3.881493,\r\n 'lb3_status': 0,\r\n 'lb4_mon': 10.0,\r\n 'lb4_status': 0,\r\n 'lb5_mon': 0.593604,\r\n 'lb5_status': 0,\r\n 'lb6_mon': 0.96824,\r\n 'lb6_status': 0,\r\n 'offset_freq': 20000000.09199998,\r\n 'offset_freqref': 20000000.0,\r\n 'offset_signal': 0.8038329999999999,\r\n 'offset_stage': -14948.0,\r\n 'reprate_freq': 250000093.93475,\r\n 'reprate_freqref': 246250000.0,\r\n 'reprate_stage': -211159.0,\r\n 'syncro_adc_channel2': 0.002084,\r\n 'system_latency': 0.514801025390625,\r\n 'system_locked': True,\r\n 'system_locked_for': 13972.88214206696,\r\n 'system_plo_ok': True,\r\n 'timestamp': 1459337054.158}\r\n```\r\n\r\nUsing a SQLite database for testing, everything seems to work properly including guessing of datatypes. However, when I switch to Postgres, I get the following traceback:\r\n\r\n```python\r\nTraceback (most recent call last):\r\n  File \"/home/iontrap/src/brush/env/bin/brush\", line 9, in <module>\r\n    load_entry_point('brush==1.0.0b2', 'console_scripts', 'brush')()\r\n  File \"/home/iontrap/src/brush/brush/cli.py\", line 55, in main\r\n    IOLoop.instance().run_sync(lambda: sweep.run())\r\n  File \"/home/iontrap/src/brush/env/lib/python3.4/site-packages/tornado/ioloop.py\", line 453, in run_sync\r\n    return future_cell[0].result()\r\n  File \"/home/iontrap/src/brush/env/lib/python3.4/site-packages/tornado/concurrent.py\", line 232, in result\r\n    raise_exc_info(self._exc_info)\r\n  File \"<string>\", line 3, in raise_exc_info\r\n  File \"/home/iontrap/src/brush/env/lib/python3.4/site-packages/tornado/gen.py\", line 282, in wrapper\r\n    yielded = next(result)\r\n  File \"/home/iontrap/src/brush/brush/sweep.py\", line 97, in run\r\n    self.write(data)\r\n  File \"/home/iontrap/src/brush/brush/sweep.py\", line 67, in write\r\n    id = table.insert(**data)\r\n  File \"/home/iontrap/src/brush/env/lib/python3.4/site-packages/playhouse/dataset.py\", line 213, in insert\r\n    return self.model_class.insert(**data).execute()\r\n  File \"/home/iontrap/src/brush/env/lib/python3.4/site-packages/peewee.py\", line 3213, in execute\r\n    cursor = self._execute()\r\n  File \"/home/iontrap/src/brush/env/lib/python3.4/site-packages/peewee.py\", line 2627, in _execute\r\n    sql, params = self.sql()\r\n  File \"/home/iontrap/src/brush/env/lib/python3.4/site-packages/peewee.py\", line 3181, in sql\r\n    return self.compiler().generate_insert(self)\r\n  File \"/home/iontrap/src/brush/env/lib/python3.4/site-packages/peewee.py\", line 1885, in generate_insert\r\n    meta.get_primary_key_fields(),\r\n  File \"/home/iontrap/src/brush/env/lib/python3.4/site-packages/peewee.py\", line 4299, in get_primary_key_fields\r\n    for field_name in self.primary_key.field_names]\r\n  File \"/home/iontrap/src/brush/env/lib/python3.4/site-packages/peewee.py\", line 4299, in <listcomp>\r\n    for field_name in self.primary_key.field_names]\r\nTypeError: unhashable type: 'list'\r\n```\r\n\r\nThe `write` method is defined as:\r\n\r\n```python\r\n    def write(self, data):\r\n        table = self.db[options.sql_table]\r\n        with self.db.transaction() as txn:\r\n            id = table.insert(**data)\r\n            if id == 1:\r\n                for index in self.indices:\r\n                    try:\r\n                        table.create_index([index])\r\n                    except OperationalError:  # index already exists\r\n                        pass\r\n```\r\n\r\nThis is using peewee 2.8.0 and a Postgres 9.3 server."},"comment":{"url":"https://api.github.com/repos/coleifer/peewee/issues/comments/203802392","html_url":"https://github.com/coleifer/peewee/issues/902#issuecomment-203802392","issue_url":"https://api.github.com/repos/coleifer/peewee/issues/902","id":203802392,"user":{"login":"mivade","id":2805515,"avatar_url":"https://avatars.githubusercontent.com/u/2805515?v=3","gravatar_id":"","url":"https://api.github.com/users/mivade","html_url":"https://github.com/mivade","followers_url":"https://api.github.com/users/mivade/followers","following_url":"https://api.github.com/users/mivade/following{/other_user}","gists_url":"https://api.github.com/users/mivade/gists{/gist_id}","starred_url":"https://api.github.com/users/mivade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mivade/subscriptions","organizations_url":"https://api.github.com/users/mivade/orgs","repos_url":"https://api.github.com/users/mivade/repos","events_url":"https://api.github.com/users/mivade/events{/privacy}","received_events_url":"https://api.github.com/users/mivade/received_events","type":"User","site_admin":false},"created_at":"2016-03-31T07:46:02Z","updated_at":"2016-03-31T07:46:02Z","body":"I was able to resolve this problem by dropping the table which had been created prior to trying to write (but was empty) and letting peewee handle the table creation itself. However, before doing this, I checked the output of `table.model_class._meta.primary_key` and `table.model_class._meta.fields`. Using `sqlite:///:memory:`, on the first run, I get:\r\n\r\n```\r\nprimary key\r\n<peewee.PrimaryKeyField object at 0x7f64787617b8>\r\nfields\r\n{'id': <peewee.PrimaryKeyField object at 0x7f64787617b8>}\r\n```\r\n\r\nand after the initial insert:\r\n\r\n```\r\nprimary key\r\n<peewee.PrimaryKeyField object at 0x7fa7322206a0>\r\nfields\r\n{'beat1_lb_mon': <peewee.FloatField object at 0x7fa7322140b8>,\r\n 'beat1_lb_status': <peewee.IntegerField object at 0x7fa7322141d0>,\r\n 'beat1_signal': <peewee.FloatField object at 0x7fa732220fd0>,\r\n 'beat1_signalaux': <peewee.FloatField object at 0x7fa732220c18>,\r\n 'beat1_waveplate': <peewee.FloatField object at 0x7fa732220cf8>,\r\n 'beat2_lb_mon': <peewee.FloatField object at 0x7fa732214160>,\r\n 'beat2_lb_status': <peewee.IntegerField object at 0x7fa7322207b8>,\r\n 'beat2_signal': <peewee.FloatField object at 0x7fa732214748>,\r\n 'beat2_signalaux': <peewee.FloatField object at 0x7fa7322143c8>,\r\n 'counter0_freq': <peewee.FloatField object at 0x7fa732214198>,\r\n 'counter0_freqref': <peewee.FloatField object at 0x7fa732220ef0>,\r\n 'counter1_freq': <peewee.FloatField object at 0x7fa732220da0>,\r\n 'counter1_freqref': <peewee.FloatField object at 0x7fa7322147b8>,\r\n 'counter2_freq': <peewee.FloatField object at 0x7fa732220f28>,\r\n 'counter2_signal': <peewee.FloatField object at 0x7fa732220e48>,\r\n 'counter3_freq': <peewee.FloatField object at 0x7fa732214208>,\r\n 'counter3_signal': <peewee.FloatField object at 0x7fa732214048>,\r\n 'counter_channels': <peewee.IntegerField object at 0x7fa732220f60>,\r\n 'counter_gatetime': <peewee.FloatField object at 0x7fa732220eb8>,\r\n 'cw1_freq': <peewee.FloatField object at 0x7fa732220e10>,\r\n 'cw2_freq': <peewee.FloatField object at 0x7fa732220828>,\r\n 'id': <peewee.PrimaryKeyField object at 0x7fa7322206a0>,\r\n 'laser_mldet_ac': <peewee.FloatField object at 0x7fa732214400>,\r\n 'laser_mldet_dc': <peewee.FloatField object at 0x7fa732220b70>,\r\n 'lb1_mon': <peewee.FloatField object at 0x7fa732214390>,\r\n 'lb1_status': <peewee.IntegerField object at 0x7fa732220b00>,\r\n 'lb2_mon': <peewee.FloatField object at 0x7fa732214278>,\r\n 'lb2_status': <peewee.IntegerField object at 0x7fa732214358>,\r\n 'lb3_mon': <peewee.FloatField object at 0x7fa732220ac8>,\r\n 'lb3_status': <peewee.IntegerField object at 0x7fa732220dd8>,\r\n 'lb4_mon': <peewee.FloatField object at 0x7fa732214320>,\r\n 'lb4_status': <peewee.IntegerField object at 0x7fa732220ba8>,\r\n 'lb5_mon': <peewee.FloatField object at 0x7fa732214080>,\r\n 'lb5_status': <peewee.IntegerField object at 0x7fa732220c88>,\r\n 'lb6_mon': <peewee.FloatField object at 0x7fa732214438>,\r\n 'lb6_status': <peewee.IntegerField object at 0x7fa732220d68>,\r\n 'offset_freq': <peewee.FloatField object at 0x7fa732220cc0>,\r\n 'offset_freqref': <peewee.FloatField object at 0x7fa732220f98>,\r\n 'offset_signal': <peewee.FloatField object at 0x7fa732220b38>,\r\n 'offset_stage': <peewee.FloatField object at 0x7fa732220e80>,\r\n 'reprate_freq': <peewee.FloatField object at 0x7fa732220c50>,\r\n 'reprate_freqref': <peewee.FloatField object at 0x7fa732214128>,\r\n 'reprate_stage': <peewee.FloatField object at 0x7fa732220748>,\r\n 'syncro_adc_channel2': <peewee.FloatField object at 0x7fa732214240>,\r\n 'system_latency': <peewee.FloatField object at 0x7fa732214780>,\r\n 'system_locked': <peewee.IntegerField object at 0x7fa7322142b0>,\r\n 'system_locked_for': <peewee.FloatField object at 0x7fa7322140f0>,\r\n 'system_plo_ok': <peewee.IntegerField object at 0x7fa7322142e8>,\r\n 'timestamp': <peewee.FloatField object at 0x7fa732220d30>}\r\n```\r\n\r\nWith Postgres, prior to the insert (where it crashes):\r\n\r\n```\r\nprimary key\r\n<peewee.PrimaryKeyField object at 0x7f4afa8afb00>\r\nfields\r\n{'id': <peewee.PrimaryKeyField object at 0x7f4afa8afb00>}\r\n```\r\n\r\nIs there any other testing you can suggest to help figure out why this fails when the empty table exists?"}}