{"action":"created","issue":{"url":"https://api.github.com/repos/coleifer/sqlite-web/issues/42","repository_url":"https://api.github.com/repos/coleifer/sqlite-web","labels_url":"https://api.github.com/repos/coleifer/sqlite-web/issues/42/labels{/name}","comments_url":"https://api.github.com/repos/coleifer/sqlite-web/issues/42/comments","events_url":"https://api.github.com/repos/coleifer/sqlite-web/issues/42/events","html_url":"https://github.com/coleifer/sqlite-web/issues/42","id":317979759,"number":42,"title":"fails to display table with foreign keys","user":{"login":"grst","id":7051479,"avatar_url":"https://avatars3.githubusercontent.com/u/7051479?v=4","gravatar_id":"","url":"https://api.github.com/users/grst","html_url":"https://github.com/grst","followers_url":"https://api.github.com/users/grst/followers","following_url":"https://api.github.com/users/grst/following{/other_user}","gists_url":"https://api.github.com/users/grst/gists{/gist_id}","starred_url":"https://api.github.com/users/grst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grst/subscriptions","organizations_url":"https://api.github.com/users/grst/orgs","repos_url":"https://api.github.com/users/grst/repos","events_url":"https://api.github.com/users/grst/events{/privacy}","received_events_url":"https://api.github.com/users/grst/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-04-26T11:04:01Z","updated_at":"2018-04-26T12:03:20Z","closed_at":null,"author_association":"NONE","body":"Using the latest version from pip, I have the following issue: \r\n\r\nWhen I click on a table that contains a foreign key, an Internal Server Error is caused with the following Traceback:\r\n\r\n```\r\n[2018-04-26 10:56:55,863] ERROR in app: Exception on /expression/ [GET]\r\nTraceback (most recent call last):\r\n  File \"/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/flask/app.py\", line 1982, in wsgi_app\r\n    response = self.full_dispatch_request()\r\n  File \"/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/flask/app.py\", line 1614, in full_dispatch_request\r\n    rv = self.handle_user_exception(e)\r\n  File \"/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/flask/app.py\", line 1517, in handle_user_exception\r\n    reraise(exc_type, exc_value, tb)\r\n  File \"/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/flask/_compat.py\", line 33,in reraise\r\n    raise value\r\n  File \"/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/flask/app.py\", line 1612, in full_dispatch_request\r\n    rv = self.dispatch_request()\r\n  File \"/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/flask/app.py\", line 1598, in dispatch_request\r\n    return self.view_functions[rule.endpoint](**req.view_args)\r\n  File \"/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/sqlite_web/sqlite_web.py\", line 201, in inner\r\n    return fn(table, *args, **kwargs)\r\n  File \"/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/sqlite_web/sqlite_web.py\", line 217, in table_structure\r\n    ds_table = dataset[table]\r\n  File \"/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/playhouse/dataset.py\", line63, in __getitem__\r\n    self.update_cache(table)\r\n  File \"/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/playhouse/dataset.py\", line92, in update_cache\r\n    literal_column_names=True)\r\n  File \"/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/playhouse/reflection.py\", line 598, in generate_models\r\n    literal_column_names=literal_column_names)\r\n  File \"/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/playhouse/reflection.py\", line 586, in introspect\r\n    related_name=related_names.get(src))\r\n  File \"/storage/apps/easybuild/software/Anaconda3/5.0.1/lib/python3.6/site-packages/playhouse/reflection.py\", line 120, in set_foreign_key\r\n    self.rel_model = model_names[foreign_key.dest_table]\r\nKeyError: 'sample'\r\n```\r\n\r\nThe SQL of the table looks like \r\n```sql\r\ncreate table sample (sample varchar(80)\r\n                     , patient varchar(80)\r\n                     , cohort varchar(10)\r\n                     , sample_type varchar(4)\r\n                     , PRIMARY KEY (sample)\r\n                     , FOREIGN KEY (cohort) references cohort(cohort)\r\n                     , FOREIGN KEY (sample_type) references sample_type(sample_type))\r\n```\r\nThe SQL of the referenced tables like\r\n\r\n```sql\r\ncreate table cohort (cohort varchar(10)\r\n                     , name text\r\n                     , PRIMARY KEY (cohort));\r\n\r\ncreate table sample_type (numeric_code varchar(2)\r\n                          , sample_type varchar(8)\r\n                          , definition text\r\n                          , PRIMARY KEY (sample_type)\r\n                          , UNIQUE(numeric_code))\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/coleifer/sqlite-web/issues/comments/384616115","html_url":"https://github.com/coleifer/sqlite-web/issues/42#issuecomment-384616115","issue_url":"https://api.github.com/repos/coleifer/sqlite-web/issues/42","id":384616115,"user":{"login":"coleifer","id":119974,"avatar_url":"https://avatars2.githubusercontent.com/u/119974?v=4","gravatar_id":"","url":"https://api.github.com/users/coleifer","html_url":"https://github.com/coleifer","followers_url":"https://api.github.com/users/coleifer/followers","following_url":"https://api.github.com/users/coleifer/following{/other_user}","gists_url":"https://api.github.com/users/coleifer/gists{/gist_id}","starred_url":"https://api.github.com/users/coleifer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coleifer/subscriptions","organizations_url":"https://api.github.com/users/coleifer/orgs","repos_url":"https://api.github.com/users/coleifer/repos","events_url":"https://api.github.com/users/coleifer/events{/privacy}","received_events_url":"https://api.github.com/users/coleifer/received_events","type":"User","site_admin":false},"created_at":"2018-04-26T12:03:20Z","updated_at":"2018-04-26T12:03:20Z","author_association":"OWNER","body":"Cool. Can you share the queries you executed? So I can replicate the issue."}}
{"actor":{"display_login":"coleifer"}}