Skip to content
Snippets Groups Projects
Commit 328c1b2a authored by Gavin M. Roy's avatar Gavin M. Roy
Browse files

Dont double-raise exceptions, handle exceptions in the same place

parent 4d73b0a3
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -8,7 +8,7 @@ The core `queries.Queries` class will automatically register support for UUIDs,
Unicode and Unicode arrays.
 
"""
__version__ = '1.8.1'
__version__ = '1.8.2'
version = __version__
 
import logging
Loading
Loading
Loading
Loading
@@ -30,7 +30,6 @@ from psycopg2 import extras
from tornado import concurrent
from tornado import gen
from tornado import ioloop
from tornado import stack_context
import psycopg2
 
from queries import pool
Loading
Loading
@@ -432,12 +431,7 @@ class TornadoSession(session.Session):
if fd not in self._connections:
LOGGER.warning('Received IO event for non-existing connection')
return
try:
self._poll_connection(fd)
except OSError as error:
self._futures[fd].set_exception(
psycopg2.OperationalError('Connection error (%s)' % error)
)
self._poll_connection(fd)
 
def _poll_connection(self, fd):
"""Check with psycopg2 to see what action to take. If the state is
Loading
Loading
@@ -448,8 +442,14 @@ class TornadoSession(session.Session):
"""
try:
state = self._connections[fd].poll()
except OSError as error:
if not self._futures[fd].exception():
self._futures[fd].set_exception(
psycopg2.OperationalError('Connection error (%s)' % error)
)
except (psycopg2.Error, psycopg2.Warning) as error:
self._futures[fd].set_exception(error)
if not self._futures[fd].exception():
self._futures[fd].set_exception(error)
else:
if state == extensions.POLL_OK:
if fd in self._futures and not self._futures[fd].done():
Loading
Loading
@@ -460,7 +460,9 @@ class TornadoSession(session.Session):
self._ioloop.update_handler(fd, ioloop.IOLoop.READ)
elif state == extensions.POLL_ERROR:
self._ioloop.remove_handler(fd)
self._futures[fd].set_exception(psycopg2.Error('Poll Error'))
if not self._futures[fd].exception():
self._futures[fd].set_exception(
psycopg2.Error('Poll Error'))
 
def _psycopg2_connect(self, kwargs):
"""Return a psycopg2 connection for the specified kwargs. Extend for
Loading
Loading
Loading
Loading
@@ -29,7 +29,7 @@ classifiers = ['Development Status :: 5 - Production/Stable',
'Topic :: Software Development :: Libraries']
 
setup(name='queries',
version='1.8.1',
version='1.8.2',
description="Simplified PostgreSQL client built upon Psycopg2",
maintainer="Gavin M. Roy",
maintainer_email="gavinmroy@gmail.com",
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment