{"action":"created","issue":{"url":"https://api.github.com/repos/kennethreitz/django-postgrespool/issues/24","labels_url":"https://api.github.com/repos/kennethreitz/django-postgrespool/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/kennethreitz/django-postgrespool/issues/24/comments","events_url":"https://api.github.com/repos/kennethreitz/django-postgrespool/issues/24/events","html_url":"https://github.com/kennethreitz/django-postgrespool/issues/24","id":46813868,"number":24,"title":"\"autocommit cannot be used inside a transaction\" error \"hides\" the actual error?","user":{"login":"YAmikep","id":1226080,"avatar_url":"https://avatars.githubusercontent.com/u/1226080?v=3","gravatar_id":"","url":"https://api.github.com/users/YAmikep","html_url":"https://github.com/YAmikep","followers_url":"https://api.github.com/users/YAmikep/followers","following_url":"https://api.github.com/users/YAmikep/following{/other_user}","gists_url":"https://api.github.com/users/YAmikep/gists{/gist_id}","starred_url":"https://api.github.com/users/YAmikep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/YAmikep/subscriptions","organizations_url":"https://api.github.com/users/YAmikep/orgs","repos_url":"https://api.github.com/users/YAmikep/repos","events_url":"https://api.github.com/users/YAmikep/events{/privacy}","received_events_url":"https://api.github.com/users/YAmikep/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2014-10-25T14:50:13Z","updated_at":"2015-02-21T23:48:07Z","closed_at":null,"body":"Hi,\r\n\r\nI was having a `autocommit cannot be used inside a transaction` error.\r\nIt was hard to find the reason but when I removed django_postgrespool (`#DATABASES['default']['ENGINE'] = 'django_postgrespool'``), the error was finally more explicit about an integrity error. I was able to fix it and the error was gone.\r\n\r\nWhy the error is not the actual error when using django_postgrespool? Isn't it possible to raise the message of the real error?\r\n\r\nThanks\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/kennethreitz/django-postgrespool/issues/comments/75400109","html_url":"https://github.com/kennethreitz/django-postgrespool/issues/24#issuecomment-75400109","issue_url":"https://api.github.com/repos/kennethreitz/django-postgrespool/issues/24","id":75400109,"user":{"login":"otanner","id":1271401,"avatar_url":"https://avatars.githubusercontent.com/u/1271401?v=3","gravatar_id":"","url":"https://api.github.com/users/otanner","html_url":"https://github.com/otanner","followers_url":"https://api.github.com/users/otanner/followers","following_url":"https://api.github.com/users/otanner/following{/other_user}","gists_url":"https://api.github.com/users/otanner/gists{/gist_id}","starred_url":"https://api.github.com/users/otanner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/otanner/subscriptions","organizations_url":"https://api.github.com/users/otanner/orgs","repos_url":"https://api.github.com/users/otanner/repos","events_url":"https://api.github.com/users/otanner/events{/privacy}","received_events_url":"https://api.github.com/users/otanner/received_events","type":"User","site_admin":false},"created_at":"2015-02-21T23:48:07Z","updated_at":"2015-02-21T23:48:07Z","body":"I ran into this problem also. I debugged the issue a little bit and I think the problem is using the Django's postgresql_psycopg2.base.DatabaseWrapper's is_usable() method.\r\n\r\nIf there is an error in the query a rollback is to be performed. Django-postgrespool's rollback method uses DatabaseWrapper class' is_usable() method to check if the connection is usable and the rollback can be performed. How ever, the is_usable() method is internally using \"SELECT 1\" to check if the connection is usable but after the query error \"SELECT 1\" cannot be executed (postgres prints \"ERROR:  current transaction is aborted, commands ignored until end of transaction block\"), so in this case is_usable() always returns False. And that's the reason the django-postgrespool's rollback is never executed either, and autocommit is tried to set True even when the connection is actually still in a transaction.\r\n\r\nThis can be tested by removing is_usable() check from _rollback method in django-postgrespool's DatabaseWrapper class. After that you see the real error message.\r\n\r\nTo fix this we would need to change the way rollback is checking database connection status. Either by overriding the is_usable() method or changing rollback to use some other style."}}