"AttributeError: 'NoneType' object has no attribute 'decode'" when executing empty script
还没有人认领这个 Issue。
评估
调研方向
从 asyncpg/connection.py 中的 Connection.execute 开始,跟踪 asyncpg/protocol/protocol.pyx 中展示的协议查询路径,尤其是 _on_result__simple_query。重现仅包含注释的查询,然后添加或更新覆盖测试,使其能够成功完成而不会出现 NoneType 解码错误,并保留非空查询的正常结果。
由索引模型根据 Issue 内容生成。
描述
Wouldn't it be natural that executing a script with only comments is a no-op returning OK?
Such that for example commenting out the contents of a migration script while developing runs the script as a no-op.
Instead what happens when running this:
import os
import asyncpg
import asyncio
async def main():
conn = await asyncpg.connect(os.environ["DATABASE_URI"])
async with conn.transaction():
await conn.execute("-- hello")
if __name__ == "__main__":
asyncio.run(main())
Is this:
Traceback (most recent call last):
File "/home/msa/dev/sandbox/pgtesting/hello.py", line 13, in <module>
asyncio.run(main())
~~~~~~~~~~~^^^^^^^^
File "/home/msa/.local/share/uv/python/cpython-3.13.0-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 194, in run
return runner.run(main)
~~~~~~~~~~^^^^^^
File "/home/msa/.local/share/uv/python/cpython-3.13.0-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/home/msa/.local/share/uv/python/cpython-3.13.0-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 721, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "/home/msa/dev/sandbox/pgtesting/hello.py", line 9, in main
await conn.execute("-- hello")
File "/home/msa/dev/sandbox/pgtesting/.venv/lib/python3.13/site-packages/asyncpg/connection.py", line 349, in execute
result = await self._protocol.query(query, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "asyncpg/protocol/protocol.pyx", line 375, in query
File "asyncpg/protocol/protocol.pyx", line 888, in asyncpg.protocol.protocol.BaseProtocol._dispatch_result
File "asyncpg/protocol/protocol.pyx", line 815, in asyncpg.protocol.protocol.BaseProtocol._on_result__simple_query
AttributeError: 'NoneType' object has no attribute 'decode'
Setup is just
mkdir hello
cd hello
uv init .
uv add asyncpg
export DATABUTTON_URI="something"
uv run hello.py # above example
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 469
- 平均合并
- 4 小时 42 分钟
- 30 天内合并 PR
- 6
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MagicStack/asyncpg 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
MagicStack/asyncpg#1357 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
MagicStack/asyncpg#997 ·
-
Connection.close(timeout=) waits forever on a pending cancel when the server never acknowledges it 未关闭
难度 4/5 3-5 天 新手友好度 68/100
MagicStack/asyncpg#1356 ·
-
难度 4/5 3-5 天 新手友好度 48/100
MagicStack/asyncpg#1354 ·
-
难度 3/5 1-2 天 新手友好度 72/100
MagicStack/asyncpg#1342 ·
查看 MagicStack/asyncpg 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 88/100
use-agent-os/agent-os#3314 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
BasedHardware/omi#15662 · 1 条评论 ·
-
documentation help wanted
难度 2/5 1-3 小时 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 62/100
AiursoftWeb/AnduinOS-2#19 ·