{"action":"created","issue":{"url":"https://api.github.com/repos/perseas/Pyrseas/issues/162","repository_url":"https://api.github.com/repos/perseas/Pyrseas","labels_url":"https://api.github.com/repos/perseas/Pyrseas/issues/162/labels{/name}","comments_url":"https://api.github.com/repos/perseas/Pyrseas/issues/162/comments","events_url":"https://api.github.com/repos/perseas/Pyrseas/issues/162/events","html_url":"https://github.com/perseas/Pyrseas/issues/162","id":229142789,"node_id":"MDU6SXNzdWUyMjkxNDI3ODk=","number":162,"title":"crash in yamltodb when table is compared to a view ","user":{"login":"tbussmann","id":6412090,"node_id":"MDQ6VXNlcjY0MTIwOTA=","avatar_url":"https://avatars0.githubusercontent.com/u/6412090?v=4","gravatar_id":"","url":"https://api.github.com/users/tbussmann","html_url":"https://github.com/tbussmann","followers_url":"https://api.github.com/users/tbussmann/followers","following_url":"https://api.github.com/users/tbussmann/following{/other_user}","gists_url":"https://api.github.com/users/tbussmann/gists{/gist_id}","starred_url":"https://api.github.com/users/tbussmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tbussmann/subscriptions","organizations_url":"https://api.github.com/users/tbussmann/orgs","repos_url":"https://api.github.com/users/tbussmann/repos","events_url":"https://api.github.com/users/tbussmann/events{/privacy}","received_events_url":"https://api.github.com/users/tbussmann/received_events","type":"User","site_admin":false},"labels":[{"id":6054584,"node_id":"MDU6TGFiZWw2MDU0NTg0","url":"https://api.github.com/repos/perseas/Pyrseas/labels/yamltodb","name":"yamltodb","color":"444444","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/perseas/Pyrseas/milestones/3","html_url":"https://github.com/perseas/Pyrseas/milestone/3","labels_url":"https://api.github.com/repos/perseas/Pyrseas/milestones/3/labels","id":2831827,"node_id":"MDk6TWlsZXN0b25lMjgzMTgyNw==","number":3,"title":"Release 0.9","description":null,"creator":{"login":"jmafc","id":558890,"node_id":"MDQ6VXNlcjU1ODg5MA==","avatar_url":"https://avatars2.githubusercontent.com/u/558890?v=4","gravatar_id":"","url":"https://api.github.com/users/jmafc","html_url":"https://github.com/jmafc","followers_url":"https://api.github.com/users/jmafc/followers","following_url":"https://api.github.com/users/jmafc/following{/other_user}","gists_url":"https://api.github.com/users/jmafc/gists{/gist_id}","starred_url":"https://api.github.com/users/jmafc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmafc/subscriptions","organizations_url":"https://api.github.com/users/jmafc/orgs","repos_url":"https://api.github.com/users/jmafc/repos","events_url":"https://api.github.com/users/jmafc/events{/privacy}","received_events_url":"https://api.github.com/users/jmafc/received_events","type":"User","site_admin":false},"open_issues":15,"closed_issues":14,"state":"open","created_at":"2017-10-12T00:06:09Z","updated_at":"2018-10-30T03:31:34Z","due_on":null,"closed_at":null},"comments":8,"created_at":"2017-05-16T19:25:22Z","updated_at":"2018-11-20T01:39:22Z","closed_at":null,"author_association":"NONE","body":"given two databases t and v each containing a simple table or view both with the same name. dbtoyaml would produce the following yaml:\r\nDatabase t:\r\n```\r\nschema public:\r\n  description: standard public schema\r\n  owner: postgres\r\n  privileges:\r\n  - PUBLIC:\r\n    - all\r\n  - postgres:\r\n    - all\r\n  table test:\r\n    columns:\r\n    - i:\r\n        type: integer\r\n    owner: myuser\r\n```\r\nDatabase v:\r\n```\r\nschema public:\r\n  description: standard public schema\r\n  owner: postgres\r\n  privileges:\r\n  - PUBLIC:\r\n    - all\r\n  - postgres:\r\n    - all\r\n  view test:\r\n    definition: \" SELECT generate_series.generate_series\\n   FROM generate_series(1,\\\r\n      \\ 10) generate_series(generate_series);\"\r\n    owner: myuser\r\n```\r\n\r\nif you compare v to t or t to v yamltodb will crash:\r\n```\r\n$ dbtoyaml v | yamltodb t\r\nTraceback (most recent call last):\r\n  File \"/usr/local/bin/yamltodb\", line 9, in <module>\r\n    load_entry_point('Pyrseas==0.8.dev0', 'console_scripts', 'yamltodb')()\r\n  File \"/Library/Python/2.7/site-packages/Pyrseas-0.8.dev0-py2.7.egg/pyrseas/yamltodb.py\", line 47, in main\r\n    stmts = db.diff_map(inmap)\r\n  File \"/Library/Python/2.7/site-packages/Pyrseas-0.8.dev0-py2.7.egg/pyrseas/database.py\", line 363, in diff_map\r\n    stmts.append(self.db.tables.diff_map(self.ndb.tables))\r\n  File \"/Library/Python/2.7/site-packages/Pyrseas-0.8.dev0-py2.7.egg/pyrseas/dbobject/table.py\", line 989, in diff_map\r\n    stmts.append(table.diff_map(intables[(sch, tbl)]))\r\n  File \"/Library/Python/2.7/site-packages/Pyrseas-0.8.dev0-py2.7.egg/pyrseas/dbobject/table.py\", line 419, in diff_map\r\n    raise KeyError(\"Table '%s' has no columns\" % intable.name)\r\nKeyError: \"Table 'test' has no columns\"\r\n```\r\nor\r\n```\r\n$ dbtoyaml t | yamltodb v\r\nTraceback (most recent call last):\r\n  File \"/usr/local/bin/yamltodb\", line 9, in <module>\r\n    load_entry_point('Pyrseas==0.8.dev0', 'console_scripts', 'yamltodb')()\r\n  File \"/Library/Python/2.7/site-packages/Pyrseas-0.8.dev0-py2.7.egg/pyrseas/yamltodb.py\", line 47, in main\r\n    stmts = db.diff_map(inmap)\r\n  File \"/Library/Python/2.7/site-packages/Pyrseas-0.8.dev0-py2.7.egg/pyrseas/database.py\", line 363, in diff_map\r\n    stmts.append(self.db.tables.diff_map(self.ndb.tables))\r\n  File \"/Library/Python/2.7/site-packages/Pyrseas-0.8.dev0-py2.7.egg/pyrseas/dbobject/table.py\", line 989, in diff_map\r\n    stmts.append(table.diff_map(intables[(sch, tbl)]))\r\n  File \"/Library/Python/2.7/site-packages/Pyrseas-0.8.dev0-py2.7.egg/pyrseas/dbobject/table.py\", line 563, in diff_map\r\n    if self.definition != inview.definition:\r\nAttributeError: 'Table' object has no attribute 'definition'\r\n```\r\nit seems yamltodb it is not detecting that `test` is of different type in the yaml compared to the database.\r\n\r\nI've tested with 0.7.3 and the current master with same result. \r\n"},"comment":{"url":"https://api.github.com/repos/perseas/Pyrseas/issues/comments/440105290","html_url":"https://github.com/perseas/Pyrseas/issues/162#issuecomment-440105290","issue_url":"https://api.github.com/repos/perseas/Pyrseas/issues/162","id":440105290,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MDEwNTI5MA==","user":{"login":"jmafc","id":558890,"node_id":"MDQ6VXNlcjU1ODg5MA==","avatar_url":"https://avatars2.githubusercontent.com/u/558890?v=4","gravatar_id":"","url":"https://api.github.com/users/jmafc","html_url":"https://github.com/jmafc","followers_url":"https://api.github.com/users/jmafc/followers","following_url":"https://api.github.com/users/jmafc/following{/other_user}","gists_url":"https://api.github.com/users/jmafc/gists{/gist_id}","starred_url":"https://api.github.com/users/jmafc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmafc/subscriptions","organizations_url":"https://api.github.com/users/jmafc/orgs","repos_url":"https://api.github.com/users/jmafc/repos","events_url":"https://api.github.com/users/jmafc/events{/privacy}","received_events_url":"https://api.github.com/users/jmafc/received_events","type":"User","site_admin":false},"created_at":"2018-11-20T01:39:22Z","updated_at":"2018-11-20T01:39:22Z","author_association":"MEMBER","body":"I've accidently discovered a more pernicious situation in my own work. Let's say you have a table `ts` with primary key name `ts_pkey`. You want to create a new table `t` with primary key `t_pkey` and a view `ts` that selects from `t`. Because you're using multiple files, your metadata directory still has around the definition for `table.ts.yaml`. `yamltodb` gets very confused because it reads both the view `ts` from the catalogs but the YAML metadata has a *table* object by that name. The solution is to remove the `table.ts.yaml` file but I think this issue requires a second look based on this scenario."}}
{"actor":{"display_login":"jmafc"}}