oracle / python-oracledb

Python driver for Oracle Database conforming to the Python DB API 2.0 specification. This is the renamed, new major release of cx_Oracle
https://oracle.github.io/python-oracledb
Other
307 stars 59 forks source link

create_pool_async requires asyncio and causes issues in pytest_asyncio #309

Closed WolfEYc closed 2 months ago

WolfEYc commented 3 months ago
  1. What versions are you using? 2.1.0
    1. Does your application call init_oracle_client()? No

      dont need any sql as it is not a sql related error, it is a connection error.

      for reference, when running the app normally it works just fine! but pytest it hangs indefinitley @anthony-tuininga

WolfEYc commented 3 months ago

I am able to work around this by doing the ole singleton trick and just create the pool on first use instead of on app startup

class PoolWrapper: pool: Optional[oracledb.AsyncConnectionPool] = None

@asynccontextmanager
async def acquire(self):
    if not self.pool:
        self.pool = oracledb.create_pool_async(password=MRTE_ORACLE_PWD, **ENV)
    async with self.pool.acquire() as conn:
        yield conn
anthony-tuininga commented 3 months ago

Hmm, something else is going on. Just for interest I changed the create_pool_async() call to be marked as async def and the test still hangs. Debugging shows that the "hang" occurs during the first attempt to perform an await. If you hit Ctrl-C the code continues until the cleanup operation takes place. So this would seem to be something with the pytest machinery or the test case in particular and not an issue with the create_pool_async() method at all! If you have other evidence that suggests otherwise, please let me know!

cjbj commented 2 months ago

@WolfEYc is there any update on this?

WolfEYc commented 2 months ago

@cjbj My singleton workaround mitigates the issue.