{"html_url": "https://github.com/dogsheep/healthkit-to-sqlite/issues/14#issuecomment-1629123734", "issue_url": "https://api.github.com/repos/dogsheep/healthkit-to-sqlite/issues/14", "id": 1629123734, "node_id": "IC_kwDOC8tyDs5hGnSW", "user": {"value": 44622670, "label": "philipp-heinrich"}, "created_at": "2023-07-10T14:46:52Z", "updated_at": "2023-07-10T14:46:52Z", "author_association": "NONE", "body": "@simonw any chance to get this fixed soon? ", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 771608692, "label": "UNIQUE constraint failed: workouts.id"}, "performed_via_github_app": null} {"html_url": "https://github.com/dogsheep/healthkit-to-sqlite/issues/14#issuecomment-1073139067", "issue_url": "https://api.github.com/repos/dogsheep/healthkit-to-sqlite/issues/14", "id": 1073139067, "node_id": "IC_kwDOC8tyDs4_9s17", "user": {"value": 343884, "label": "lchski"}, "created_at": "2022-03-20T00:54:18Z", "updated_at": "2022-03-20T00:54:18Z", "author_association": "NONE", "body": "Update: this appears to be because of running the command twice without clearing the DB in between. Tries to insert a Workout that already exists, causing a collision on the (auto-generated) `id` column. Had a different error with a clean DB, likely due to the workout points format; will make a new issue for that.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 771608692, "label": "UNIQUE constraint failed: workouts.id"}, "performed_via_github_app": null} {"html_url": "https://github.com/dogsheep/healthkit-to-sqlite/issues/14#issuecomment-1073123231", "issue_url": "https://api.github.com/repos/dogsheep/healthkit-to-sqlite/issues/14", "id": 1073123231, "node_id": "IC_kwDOC8tyDs4_9o-f", "user": {"value": 343884, "label": "lchski"}, "created_at": "2022-03-19T22:39:29Z", "updated_at": "2022-03-19T22:39:29Z", "author_association": "NONE", "body": "I have this issue, too, with a fresh export. None of my `Workout` entries in `export.xml` have an `id` key, though [the sample `export.xml` in the tests folder doesn\u2019t either](https://github.com/dogsheep/healthkit-to-sqlite/blob/main/tests/zip_contents/apple_health_export/export.xml#L14-L21), so I don\u2019t think this is the culprit. Indeed, it seems @simonw is using the [`hash_id` function from `sqlite_utils`](https://sqlite-utils.datasette.io/en/stable/python-api.html#setting-an-id-based-on-the-hash-of-the-row-contents), which creates a column (`id`, in this case) based on a hash of the row\u2019s contents.\r\n\r\nWhen I run the script, a `workouts` table is created, with one entry: my first workout. No `workout_points` table is created, as [I\u2019d expect from `utils.py`](https://github.com/dogsheep/healthkit-to-sqlite/blob/main/healthkit_to_sqlite/utils.py#L89-L90). I then get essentially the same error as noted in this thread:\r\n\r\n```Importing from HealthKit [###################################-] 98% 00:00:01\r\nTraceback (most recent call last):\r\n File \"/Users/lchski/.pyenv/versions/3.10.3/bin/healthkit-to-sqlite\", line 8, in \r\n sys.exit(cli())\r\n File \"/Users/lchski/.pyenv/versions/3.10.3/lib/python3.10/site-packages/click/core.py\", line 1128, in __call__\r\n return self.main(*args, **kwargs)\r\n File \"/Users/lchski/.pyenv/versions/3.10.3/lib/python3.10/site-packages/click/core.py\", line 1053, in main\r\n rv = self.invoke(ctx)\r\n File \"/Users/lchski/.pyenv/versions/3.10.3/lib/python3.10/site-packages/click/core.py\", line 1395, in invoke\r\n return ctx.invoke(self.callback, **ctx.params)\r\n File \"/Users/lchski/.pyenv/versions/3.10.3/lib/python3.10/site-packages/click/core.py\", line 754, in invoke\r\n return __callback(*args, **kwargs)\r\n File \"/Users/lchski/.pyenv/versions/3.10.3/lib/python3.10/site-packages/healthkit_to_sqlite/cli.py\", line 57, in cli\r\n convert_xml_to_sqlite(fp, db, progress_callback=bar.update, zipfile=zf)\r\n File \"/Users/lchski/.pyenv/versions/3.10.3/lib/python3.10/site-packages/healthkit_to_sqlite/utils.py\", line 34, in convert_xml_to_sqlite\r\n workout_to_db(el, db, zipfile)\r\n File \"/Users/lchski/.pyenv/versions/3.10.3/lib/python3.10/site-packages/healthkit_to_sqlite/utils.py\", line 57, in workout_to_db\r\n pk = db[\"workouts\"].insert(record, alter=True, hash_id=\"id\").last_pk\r\n File \"/Users/lchski/.pyenv/versions/3.10.3/lib/python3.10/site-packages/sqlite_utils/db.py\", line 2822, in insert\r\n return self.insert_all(\r\n File \"/Users/lchski/.pyenv/versions/3.10.3/lib/python3.10/site-packages/sqlite_utils/db.py\", line 2950, in insert_all\r\n self.insert_chunk(\r\n File \"/Users/lchski/.pyenv/versions/3.10.3/lib/python3.10/site-packages/sqlite_utils/db.py\", line 2715, in insert_chunk\r\n result = self.db.execute(query, params)\r\n File \"/Users/lchski/.pyenv/versions/3.10.3/lib/python3.10/site-packages/sqlite_utils/db.py\", line 458, in execute\r\n return self.conn.execute(sql, parameters)\r\nsqlite3.IntegrityError: UNIQUE constraint failed: workouts.id\r\n```\r\n\r\nAre there maybe duplicate workouts in the data, which\u2019d cause multiple rows to share the same `id`? It\u2019s strange, though, that no `workout_points` is created at all. Export created from iOS 15.3.1.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 771608692, "label": "UNIQUE constraint failed: workouts.id"}, "performed_via_github_app": null} {"html_url": "https://github.com/dogsheep/healthkit-to-sqlite/issues/14#issuecomment-798468572", "issue_url": "https://api.github.com/repos/dogsheep/healthkit-to-sqlite/issues/14", "id": 798468572, "node_id": "MDEyOklzc3VlQ29tbWVudDc5ODQ2ODU3Mg==", "user": {"value": 1234956, "label": "n8henrie"}, "created_at": "2021-03-13T14:47:31Z", "updated_at": "2021-03-13T14:47:31Z", "author_association": "NONE", "body": "Ok, new PR works. I'm not `git` enough so I just force-pushed over the old one.\r\n\r\nI still end up with a lot of activities that are missing an `id` and therefore skipped (since this is used as the primary key). For example:\r\n\r\n```\r\n{'workoutActivityType': 'HKWorkoutActivityTypeRunning', 'duration': '35.31666666666667', 'durationUnit': 'min', 'totalDistance': '4.010870267636999', 'totalDistanceUnit': 'mi', 'totalEnergyBurned': '660.3516235351562', 'totalEnergyBurnedUnit': 'Cal', 'sourceName': 'Strava', 'sourceVersion': '22810', 'creationDate': '2020-07-16 13:38:26 -0700', 'startDate': '2020-07-16 06:38:26 -0700', 'endDate': '2020-07-16 07:13:45 -0700'}\r\n```\r\n\r\nI also end up with some unhappy characters (in the skipped events), such as: `'sourceName': 'Nathan\u2019s Apple\\xa0Watch',`.\r\n\r\nBut it's successfully making it through the file, and the resulting db opens in datasette, so I'd call that progress.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 771608692, "label": "UNIQUE constraint failed: workouts.id"}, "performed_via_github_app": null} {"html_url": "https://github.com/dogsheep/healthkit-to-sqlite/issues/14#issuecomment-798436026", "issue_url": "https://api.github.com/repos/dogsheep/healthkit-to-sqlite/issues/14", "id": 798436026, "node_id": "MDEyOklzc3VlQ29tbWVudDc5ODQzNjAyNg==", "user": {"value": 1234956, "label": "n8henrie"}, "created_at": "2021-03-13T14:23:16Z", "updated_at": "2021-03-13T14:23:16Z", "author_association": "NONE", "body": "This PR allows my import to succeed.\r\n\r\nIt looks like some events don't have an `id`, but do have `HKExternalUUID` (which gets turned into `metadata_HKExternalUUID`), so I use this as a fallback.\r\n\r\nIf a record has neither of these, I changed it to just print the record (for debugging) and `return`.\r\n\r\nFor some odd reason this ran fine at first, and now (after removing the generated db and trying again) I'm getting a different error (duplicate column name).\r\n\r\nLooks like it may have run when I had two successive runs without remembering to delete the db in between. Will try to refactor.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 771608692, "label": "UNIQUE constraint failed: workouts.id"}, "performed_via_github_app": null}