MagicStack / MagicStack/asyncpg

Impossible to select arbitrary column when using SQLAlchemy

未关闭
#681 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
8.1k
派生
468
PR 合并指标
30 天内没有已合并 PR

描述

* **asyncpg version**: asyncpg==0.21.0
* **PostgreSQL version**: 13
* **Python version**: 3.6
* **Platform**: Alpine Linux (3.8)
* **Do you use pgbouncer?**: no
* **Did you install asyncpg with pip?**: yes
* **If you built asyncpg locally, which version of Cython did you use?**: N/A
* **Can the issue be reproduced under both asyncio and
[uvloop](https://github.com/magicstack/uvloop)?**: I don't know, I'm using uvloop right now

I'm trying to use `asyncpg` with `SQLAlchemy` on a project of mine. However, the following constructs to select a subset of columns in the underlying table doesn't work:

```python
query = mytable.select(mytable.c.date)
results = await database.fetch_all(query)
```

This raises the following error:

```
File "./main.py", line 140, in post_telemetry
tel_results = await vmo.database.fetch_all(tel_query)
File "/usr/local/lib/python3.6/site-packages/databases/core.py", line 140, in fetch_all
return await connection.fetch_all(query, values)
File "/usr/local/lib/python3.6/site-packages/databases/core.py", line 239, in fetch_all
return await self._connection.fetch_all(built_query)
File "/usr/local/lib/python3.6/site-packages/databases/backends/postgres.py", line 160, in fetch_all
rows = await self._connection.fetch(query, *args)
File "/usr/local/lib/python3.6/site-packages/asyncpg/connection.py", line 443, in fetch
return await self._execute(query, args, 0, timeout)
File "/usr/local/lib/python3.6/site-packages/asyncpg/connection.py", line 1446, in _execute
query, args, limit, timeout, return_status=return_status)
File "/usr/local/lib/python3.6/site-packages/asyncpg/connection.py", line 1454, in __execute
return await self._do_execute(query, executor, timeout)
File "/usr/local/lib/python3.6/site-packages/asyncpg/connection.py", line 1466, in _do_execute
stmt = await self._get_statement(query, None)
File "/usr/local/lib/python3.6/site-packages/asyncpg/connection.py", line 351, in _get_statement
statement = await self._protocol.prepare(stmt_name, query, timeout)
File "asyncpg/protocol/protocol.pyx", line 163, in prepare
asyncpg.exceptions.DatatypeMismatchError: argument of AND must be type boolean, not type timestamp with time zone
```

As far as I can't tell, `asyncpg` doesn't seem to support this feature [that is present in SQLAlchemy since version 1.4](https://docs.sqlalchemy.org/en/14/core/tutorial.html#selecting-specific-columns), but I may be wrong.

Let me know if you need additional information.

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,使用报告中提到的 Python、PostgreSQL 和 package 版本重现 SQLAlchemy 的列选择查询,然后检查通过 databases 交给 asyncpg 的 SQL。确认生成的查询是否会导致数据类型不匹配错误;当选择部分列能够成功执行时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
postgresql, python, sqlalchemy
领域
backend, databases
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。