python asyncpg TypeError: _execute() got an unexpected keyword argument 'record_class'

python asyncpg TypeError: _execute() got an unexpected keyword argument 'record_class'

所以我正在使用 aiohttp 和 asyncpg 开发 REST API。这是我对处理程序的基本看法:

from aiohttp.web_urldispatcher import View
from asyncpgsa import PG


class BaseView(View):
    URL_PATH: str

    @property
    def pg(self) -> PG:
        return self.request.app['pg']

我正在尝试对我的一个表执行 select 查询并获取行:

query = select([regions_table.c.region_id]).select_from(regions_table)
regions = await self.pg.fetch(query)

但是,我从标题中得到错误:

File "blahblahblah/env/lib/python3.8/site-packages/asyncpg/connection.py", line 583, in fetch
    return await self._execute(
TypeError: _execute() got an unexpected keyword argument 'record_class'

我的猜测是 fetch 和 fetchrow 在调用没有参数的 execute() 时有一个参数 'record_class'。这是 fetch() 的实现:

    async def fetch(
        self,
        query,
        *args,
        timeout=None,
        record_class=None
    ) -> list:
        
        self._check_open()
        return await self._execute(
            query,
            args,
            0,
            timeout,
            record_class=record_class,
        )

这里是 _execute():

    def _execute(self, query, args, limit, timeout, return_status=False):
        query, compiled_args = compile_query(query, dialect=self._dialect)
        args = compiled_args or args
        return super()._execute(query, args, limit, timeout,
                                return_status=return_status)

但我还没有看到任何相关的问题,并且来自其他项目的代码可以很好地处理相同的查询。也许我错过了有关文档或处理这些库的内容?欢迎任何建议。

问题是由于 asyncpg 与其包装器 asyncpgsa 之间的不兼容造成的。我上面粘贴的 fetch() 片段来自 asyncpg v0.22 的 asyncpg/connection.py,而 _execute() 片段来自 asyncpgsa v0.16.5 的 asyncpgsa/connection.py,现在甚至不是有效的版本。版本 0.17.0 与 0.22 asyncpg 及其 record_class 字段兼容,而 0.16.5 显然已过时。 所以,我必须做的是重新配置我的 requirements.txt:

asyncpgsa==0.27.0
setuptools~=54.1.2

我相信任何从 skratch 制作 venv 的人都不会遇到同样的问题。我用的是半年前做的项目的需求,所以出现了不兼容的情况。这里的士气是:不要相信 copypasta。