`get_settings()` can get out of sync after a transaction with an error is rolled back
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 42/100
调研方向
从提供的 Python 复现程序开始,重点关注事务回滚路径和连接的 get_settings() 入口点。确认事务错误后的回滚与干净回滚之间的差异,然后追踪 client_encoding 状态是如何刷新的;当 get_settings() 在回滚后报告 UTF8,且后续的文本参数查询成功时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
- asyncpg version: 0.30.0
- PostgreSQL version: 17.2
- Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: No - Python version: 3.12.2
- Platform: Linux
- Do you use pgbouncer?: No
- Did you install asyncpg with pip?: Yes
- If you built asyncpg locally, which version of Cython did you use?:
- Can the issue be reproduced under both asyncio and
uvloop?: Only checked asyncio but it doesn't seem likely to matter
#!/usr/bin/env python3
import asyncio
import asyncpg
async def _check_encoding(con):
current_encoding = (await con.fetch(
"select current_setting('client_encoding')")
)[0]['current_setting']
print(current_encoding)
print(con.get_settings().client_encoding)
async def test(dsn):
con = await asyncpg.connect(dsn)
print("Orig")
await _check_encoding(con)
tran = con.transaction()
await tran.start()
await con.execute("set client_encoding to 'latin1'")
print("In transaction:")
await _check_encoding(con)
try:
await con.fetch("select 1 + 'a'")
except Exception:
pass
await tran.rollback()
print("After rollback:")
await _check_encoding(con)
res = await con.fetch('select $1::text', '💩')
print(res)
asyncio.run(test(
'postgres:///main?user=edgedb&port=5656&host=localhost'
))
In a transaction, if I set client_encoding to something, and then the transaction has an error and is rolled back, the client_encoding that get_settings() returns is never reverted.
If the transaction is rolled back without an error occuring, the right thing happens.
Output:
Orig
UTF8
UTF_8
In transaction:
LATIN1
LATIN1
After rollback:
UTF8
LATIN1
Traceback (most recent call last):
File "asyncpg/protocol/prepared_stmt.pyx", line 175, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg
File "asyncpg/protocol/codecs/base.pyx", line 227, in asyncpg.protocol.protocol.Codec.encode
File "asyncpg/protocol/codecs/base.pyx", line 129, in asyncpg.protocol.protocol.Codec.encode_scalar
File "asyncpg/pgproto/./codecs/text.pyx", line 29, in asyncpg.pgproto.pgproto.text_encode
File "asyncpg/pgproto/./codecs/text.pyx", line 17, in asyncpg.pgproto.pgproto.as_pg_string_and_size
UnicodeEncodeError: 'latin-1' codec can't encode character '\U0001f4a9' in position 0: ordinal not in range(256)
I would expect
After rollback:
UTF8
UTF8
and no encoding error.
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 474
- 平均合并
- 3 天 14 小时
- 30 天内合并 PR
- 17
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MagicStack/asyncpg 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 72/100
MagicStack/asyncpg#1342 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 56/100
MagicStack/asyncpg#1340 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 28/100
MagicStack/asyncpg#1337 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 42/100
MagicStack/asyncpg#1330 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 38/100
MagicStack/asyncpg#1322 ·
维护者通常 1 天内回复
查看 MagicStack/asyncpg 的全部 Issue
相似的 Issue
-
adr
难度 2/5 1-3 小时 新手友好度 72/100
kristofdegrave/homeassistant-smart-charging#1607 ·
维护者通常 1 天内回复
-
namespace operations
难度 2/5 1-3 小时 新手友好度 64/100
EclipseFdn/open-vsx.org#13665 ·
维护者通常 1 天内回复
-
doc good first issue help wanted
难度 2/5 1-3 小时 新手友好度 68/100
collective/icalendar#1865 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
canonical/opentelemetry-collector-operator#409 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
mozilla/addons-release-tests#1243 ·
维护者通常 1 天内回复