FSX / momoko

Wraps (asynchronous) Psycopg2 for Tornado.
http://momoko.61924.nl/
Other
358 stars 73 forks source link

AttributeError: 'Future' object has no attribute 'set_exc_info' #164

Closed gvfnix closed 6 years ago

gvfnix commented 6 years ago

Code:

    @tornado.gen.coroutine
    def __write_namebase(self, namebase_dict):
        sql_query = """
            insert into eissd.namebase (title, region, campaign, tariff, tariff_comment)
                values ('{title}', {region}, {campaign}, '{tariff}',  '{tariff_comment}')
            on conflict(title) do update
                set region={region}, campaign={campaign}, tariff='{tariff}',
                    tariff_comment='{tariff_comment}', loaded=false
        """.format(**namebase_dict)
        yield self.connection_pool.execute(sql_query)
        raise tornado.gen.Return()
...
                try:
                    yield self.__write_namebase(namebase)
                except Exception as exc:
                    self.log.error(exc)

Trace:

ERROR:asyncio:Exception in callback None
handle: <Handle cancelled>
Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/momoko/connection.py", line 718, in _io_callback
    state = self.connection.poll()
psycopg2.ProgrammingError: permission denied for relation namebase

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.4/asyncio/events.py", line 125, in _run
    self._callback(*self._args)
  File "/usr/lib64/python3.4/site-packages/tornado/platform/asyncio.py", line 117, in _handle_events
    handler_func(fileobj, events)
  File "/usr/lib64/python3.4/site-packages/tornado/stack_context.py", line 276, in null_wrapper
    return fn(*args, **kwargs)
  File "/usr/lib/python3.4/site-packages/momoko/connection.py", line 721, in _io_callback
    future.set_exc_info(sys.exc_info())
AttributeError: 'Future' object has no attribute 'set_exc_info'

Environment:

# pip --version
pip 10.0.1 from /usr/lib/python3.4/site-packages/pip (python 3.4)
# pip list
Package         Version
--------------- -------
backports-abc   0.5    
lxml            4.2.1  
Momoko          2.2.4  
pip             10.0.1 
psycopg2        2.7.4  
psycopg2-binary 2.7.4  
setuptools      19.2   
SQLAlchemy      1.2.7  
tornado         5.0.2  

Tornado doc says:

The exc_info and set_exc_info methods are no longer available on Python 3.

sbunatyan commented 6 years ago

According to Tornado 5.0 release notes:

The exc_info and set_exc_info methods are no longer present. Use tornado.concurrent.future_set_exc_info to replace the latter, and raise the exception with ~asyncio.Future.result to replace the former.

friedcell commented 6 years ago

I don't think momoko is compatible with Tornado 5.x: This is the 2.x version of Momoko. It requires 4.0 <= Tornado < 5.0

papaslen commented 6 years ago

@friedcell So it looks like there is no way to use momoko with Tornado 5+ properly? And i guess we don't have async db driver for latest Tornado releases anymore? @gvfnix How did you handle it?

friedcell commented 6 years ago

@papaslen we're experimenting with a wrapper around https://github.com/aio-libs/aiopg to provide the same API but there are some differences on how it handles returning connections to the pool (for us mostly relevant in tests)

papaslen commented 6 years ago

@friedcell Oh, thanks for the rapid response) I definitely will take a look on aiopg.