scarletcafe / jishaku

A debugging and testing cog for discord.py rewrite bots.
https://jishaku.readthedocs.io/en/latest/
MIT License
541 stars 181 forks source link

Fix asyncpg.Pool usage #183

Closed daggy1234 closed 2 years ago

daggy1234 commented 2 years ago

Rationale

There is an error in the importing of Pool from asyncpg as it is asyncpg.pool.Pool.

Currently an error is produced

dagbot    | Traceback (most recent call last):
dagbot    |   File "/usr/local/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 917, in _load_from_module_spec
dagbot    |     spec.loader.exec_module(lib)  # type: ignore
dagbot    |   File "<frozen importlib._bootstrap_external>", line 783, in exec_module
dagbot    |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
dagbot    |   File "/usr/local/lib/python3.8/site-packages/jishaku/__init__.py", line 15, in <module>
dagbot    |     from jishaku.cog import *  # noqa: F401
dagbot    |   File "/usr/local/lib/python3.8/site-packages/jishaku/cog.py", line 27, in <module>
dagbot    |     from jishaku.features.sql import SQLFeature
dagbot    |   File "/usr/local/lib/python3.8/site-packages/jishaku/features/sql.py", line 110, in <module>
dagbot    |     @adapter(asyncpg.Connection, asyncpg.Pool)
dagbot    | AttributeError: module 'asyncpg' has no attribute 'Pool'
dagbot    | 
dagbot    | The above exception was the direct cause of the following exception:
dagbot    | 
dagbot    | Traceback (most recent call last):
dagbot    |   File "/usr/local/lib/python3.8/runpy.py", line 194, in _run_module_as_main
dagbot    |     return _run_code(code, main_globals, None,
dagbot    |   File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code
dagbot    |     exec(code, run_globals)
dagbot    |   File "/dagbot/__main__.py", line 20, in <module>
dagbot    |     asyncio.run(start_bot())
dagbot    |   File "/usr/local/lib/python3.8/asyncio/runners.py", line 44, in run
dagbot    |     return loop.run_until_complete(main)
dagbot    |   File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
dagbot    |     return future.result()
dagbot    |   File "/dagbot/__main__.py", line 9, in start_bot
dagbot    |     await dagbot.startdagbot()
dagbot    |   File "/dagbot/bot.py", line 147, in startdagbot
dagbot    |     await self.load_extensionsa()
dagbot    |   File "/dagbot/bot.py", line 110, in load_extensionsa
dagbot    |     await self.load_extension("jishaku")
dagbot    |   File "/usr/local/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 995, in load_extension
dagbot    |     await self._load_from_module_spec(spec, name)
dagbot    |   File "/usr/local/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 920, in _load_from_module_spec
dagbot    |     raise errors.ExtensionFailed(key, e) from e
dagbot    | discord.ext.commands.errors.ExtensionFailed: Extension 'jishaku' raised an error: AttributeError: module 'asyncpg' has no attribute 'Pool'

Summary of changes made

Simply switched the import. https://magicstack.github.io/asyncpg/current/api/index.html?highlight=pool#asyncpg.pool.Pool

Checklist

scarletcafe commented 2 years ago

I can't repro this. What version of asyncpg are you using?

scarletcafe commented 2 years ago

Judging by https://github.com/MagicStack/asyncpg/commit/0e0eb8d35e4804f681ebac4bc0e77a538d0f4fea, this was changed in the 0.22.0 tree, nearly 2 years ago. We're currently on 0.26.0, so your asyncpg is out of date by quite a bit. I'll merge this anyway since it doesn't break the current version and extends compatibility.