Jaymon / prom

A PostgreSQL or SQLite orm for Python
MIT License
22 stars 4 forks source link

Prom async bug #9

Closed Jaymon closed 10 months ago

Jaymon commented 9 years ago

On one of our tests, the foo/bar script uses greenthreads, and when they both start up without a wait between them they will cause a connection pool error

c1 = ScriptClient("foo/bar")
r1 = c1.run_async()

c2 = ScriptClient("foo/bar")
r2 = c2.run_async()

c1.wait()
c2.wait()

The error:

'NoneType' object has no attribute 'getconn'
Traceback (most recent call last):
  ...
  File "/usr/local/lib/python2.7/dist-packages/prom/query.py", line 573, in get_one
    d = self._query('get_one')
  File "/usr/local/lib/python2.7/dist-packages/prom/query.py", line 682, in _query
    return getattr(i, method_name)(s, self) # i.method_name(schema, query)
  File "/usr/local/lib/python2.7/dist-packages/prom/interface/base.py", line 485, in get_one
    ret = self._get_query(self._get_one, schema, query, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/prom/decorators.py", line 58, in wrapper
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/prom/interface/base.py", line 453, in _get_query
    with self.connection(**kwargs) as connection:
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/usr/local/lib/python2.7/dist-packages/prom/interface/base.py", line 177, in connection
    self.raise_error(e)
  File "/usr/local/lib/python2.7/dist-packages/prom/interface/base.py", line 167, in connection
    connection = self.get_connection()
  File "/usr/local/lib/python2.7/dist-packages/prom/interface/postgres.py", line 98, in get_connection
    connection = self.connection_pool.getconn()
AttributeError: 'NoneType' object has no attribute 'getconn'

This only shows up in tests, I think the reason why is because we've cleared all the tables and so the prom error handling table creation code kicks on the first connection and then the second connection causes a problem?

Jaymon commented 3 years ago

This can be closed when https://github.com/Jaymon/prom/issues/138 is implemented