{"action":"created","issue":{"url":"https://api.github.com/repos/ponyorm/pony/issues/158","repository_url":"https://api.github.com/repos/ponyorm/pony","labels_url":"https://api.github.com/repos/ponyorm/pony/issues/158/labels{/name}","comments_url":"https://api.github.com/repos/ponyorm/pony/issues/158/comments","events_url":"https://api.github.com/repos/ponyorm/pony/issues/158/events","html_url":"https://github.com/ponyorm/pony/issues/158","id":131378679,"number":158,"title":"Если вызвать `.flush()` то теряется транзакционная целостность.","user":{"login":"vladlutkov","id":4979124,"avatar_url":"https://avatars.githubusercontent.com/u/4979124?v=3","gravatar_id":"","url":"https://api.github.com/users/vladlutkov","html_url":"https://github.com/vladlutkov","followers_url":"https://api.github.com/users/vladlutkov/followers","following_url":"https://api.github.com/users/vladlutkov/following{/other_user}","gists_url":"https://api.github.com/users/vladlutkov/gists{/gist_id}","starred_url":"https://api.github.com/users/vladlutkov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vladlutkov/subscriptions","organizations_url":"https://api.github.com/users/vladlutkov/orgs","repos_url":"https://api.github.com/users/vladlutkov/repos","events_url":"https://api.github.com/users/vladlutkov/events{/privacy}","received_events_url":"https://api.github.com/users/vladlutkov/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ponyorm/pony/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/ponyorm/pony/milestones/3","html_url":"https://github.com/ponyorm/pony/milestones/0.6.3","labels_url":"https://api.github.com/repos/ponyorm/pony/milestones/3/labels","id":1563836,"number":3,"title":"0.6.3","description":"","creator":{"login":"kozlovsky","id":2931136,"avatar_url":"https://avatars.githubusercontent.com/u/2931136?v=3","gravatar_id":"","url":"https://api.github.com/users/kozlovsky","html_url":"https://github.com/kozlovsky","followers_url":"https://api.github.com/users/kozlovsky/followers","following_url":"https://api.github.com/users/kozlovsky/following{/other_user}","gists_url":"https://api.github.com/users/kozlovsky/gists{/gist_id}","starred_url":"https://api.github.com/users/kozlovsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kozlovsky/subscriptions","organizations_url":"https://api.github.com/users/kozlovsky/orgs","repos_url":"https://api.github.com/users/kozlovsky/repos","events_url":"https://api.github.com/users/kozlovsky/events{/privacy}","received_events_url":"https://api.github.com/users/kozlovsky/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":1,"state":"open","created_at":"2016-02-04T17:06:37Z","updated_at":"2016-02-04T18:17:27Z","due_on":null,"closed_at":null},"comments":9,"created_at":"2016-02-04T15:15:34Z","updated_at":"2016-02-04T18:28:50Z","closed_at":"2016-02-04T18:17:27Z","body":"``` python\r\nfrom pony.orm import Database, db_session\r\n\r\ndb = Database()\r\n\r\n\r\nclass TestTable(db.Entity):\r\n    pass\r\n\r\n\r\ndef init_database():\r\n    db.bind(\"sqlite\", \":memory:\")\r\n    db.generate_mapping(create_tables=True)\r\n\r\n\r\ndef clear_database():\r\n    db.drop_all_tables(with_all_data=True)\r\n    db.create_tables()\r\n\r\nif __name__ == \"__main__\":\r\n    init_database()\r\n\r\n    try:\r\n        with db_session:\r\n            entity = TestTable()\r\n            entity.flush()\r\n            raise ValueError()\r\n    except ValueError as exc:\r\n        print(exc.args)\r\n    with db_session:\r\n        # в транзакции ошибка, а в таблице запись уже есть!\r\n        if len(TestTable.select()) != 0:\r\n            print(\"Таблица не пуста\")\r\n\r\n    clear_database()\r\n\r\n    try:\r\n        with db_session:\r\n            entity = TestTable()\r\n            raise ValueError()\r\n    except ValueError as exc:\r\n        print(exc.args)\r\n    with db_session:\r\n        # в транзакции ошибка, а в таблице записи нет, все ок\r\n        if len(TestTable.select()) == 0:\r\n            print(\"Все в порядке!\")\r\n```\r\n\r\nЧто как бы очень критичный баг.\r\n\r\nНу и менее важная проблема - как мне получить `id` только что созданного элемента?"},"comment":{"url":"https://api.github.com/repos/ponyorm/pony/issues/comments/179983589","html_url":"https://github.com/ponyorm/pony/issues/158#issuecomment-179983589","issue_url":"https://api.github.com/repos/ponyorm/pony/issues/158","id":179983589,"user":{"login":"socketpair","id":1157412,"avatar_url":"https://avatars.githubusercontent.com/u/1157412?v=3","gravatar_id":"","url":"https://api.github.com/users/socketpair","html_url":"https://github.com/socketpair","followers_url":"https://api.github.com/users/socketpair/followers","following_url":"https://api.github.com/users/socketpair/following{/other_user}","gists_url":"https://api.github.com/users/socketpair/gists{/gist_id}","starred_url":"https://api.github.com/users/socketpair/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/socketpair/subscriptions","organizations_url":"https://api.github.com/users/socketpair/orgs","repos_url":"https://api.github.com/users/socketpair/repos","events_url":"https://api.github.com/users/socketpair/events{/privacy}","received_events_url":"https://api.github.com/users/socketpair/received_events","type":"User","site_admin":false},"created_at":"2016-02-04T18:28:50Z","updated_at":"2016-02-04T18:28:50Z","body":"Кстати, насчёт исключений. На мой взгляд, причина несрабатывания коммита может быть только одна (первая встретившаяся) (я не говорю о цепочке исключений типа `raise from`).\r\n\r\nНа мой взгляд, в `CommitException` должны преобразовываться только исключения пришедшие из драйвера БД. А исключения из хуков должны пробрасываться напрямую.\r\n\r\nА так -- как раз таки наоборот, однородно не получается обрабатывать, и нужно обрабатывать оба вида исключений - и нативное (из хука) и `CommitException`. Потому что  `flush()` может вызваться опосредовано, а может и не вызваться, сразу перейдя к коммиту.\r\n\r\n\r\n"}}