Cannot use datetimes before UNIX epoch on Windows
还没有人认领这个 Issue。
评估
调研方向
从 py-pgproto's codecs/datetime.pyx 中链接的那一行开始,并将其行为与所引用的 CPython Windows issue 进行比较。在 Windows 上通过 executemany() 重现对 datetime.datetime(1969, 12, 31) 的 bind。完成标准是:早于 UNIX 纪元的 datetimes 在编码过程中不再引发 OSError。
由索引模型根据 Issue 内容生成。
描述
- asyncpg version: 0.29.0
- PostgreSQL version: 15.5
- Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: Local PostgreSQL install - Python version: 3.10.1
- Platform: Windows
- 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?: N/A
If I have this query:
INSERT INTO process.start_and_end (user_id, process_id, start_dt, end_dt) VALUES ($1, $2, $3, $4);
and in Python I do:
await conn.executemany(query, [(1325, 1001, datetime.datetime(1969, 12, 31, 0, 0), None)])
this line throws the following exception:
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/datetime.pyx", line 222, in asyncpg.pgproto.pgproto.timestamptz_encode
OSError: [Errno 22] Invalid argument
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "main.py", line 919, in <module>
loop.run_until_complete(async_main())
File "C:\Scoop\apps\python\current\lib\asyncio\base_events.py", line 641, in run_until_complete
return future.result()
[...]
File "main.py", line 401, in __insert_tape
await conn.executemany(query, [(1325, 1001, datetime.datetime(1969, 12, 31, 0, 0), None)])
File ".venv\lib\site-packages\asyncpg\connection.py", line 391, in executemany
return await self._executemany(command, args, timeout)
File ".venv\lib\site-packages\asyncpg\connection.py", line 1911, in _executemany
result, _ = await self._do_execute(query, executor, timeout)
File ".venv\lib\site-packages\asyncpg\connection.py", line 1945, in _do_execute
result = await executor(stmt, None)
File "asyncpg\protocol\protocol.pyx", line 267, in bind_execute_many
File "asyncpg\protocol\coreproto.pyx", line 974, in asyncpg.protocol.protocol.CoreProtocol._bind_execute_many_more
File "asyncpg\protocol\protocol.pyx", line 230, in genexpr
File "asyncpg\protocol\prepared_stmt.pyx", line 204, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg
asyncpg.exceptions.DataError: invalid input for query argument $3 in element #0 of executemany() sequence: datetime.datetime(1969, 12, 31, 0, 0) ([Errno 22] Invalid argument)
Digging into it a bit more, I found that the culprit is this line in the codec for datetime objects, which is related to this old CPython issue on Windows: https://github.com/python/cpython/issues/80940.
The fix looks quite simple, but unfortunately I do not have the time to work on that, so I'm opening an issue instead of a PR.
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 469
- 平均合并
- 3 天 21 小时
- 30 天内合并 PR
- 15
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MagicStack/asyncpg 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 72/100
MagicStack/asyncpg#1342 ·
-
难度 3/5 1-2 天 新手友好度 56/100
MagicStack/asyncpg#1340 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 28/100
MagicStack/asyncpg#1337 ·
-
难度 4/5 3-5 天 新手友好度 42/100
MagicStack/asyncpg#1330 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 38/100
MagicStack/asyncpg#1322 ·
查看 MagicStack/asyncpg 的全部 Issue
相似的 Issue
-
correction metadata
难度 2/5 1-3 小时 新手友好度 68/100
acl-org/acl-anthology#10104 · 1 条评论 ·
维护者通常 1 天内回复
-
bug status/needs-triage
难度 2/5 1-3 小时 新手友好度 86/100
prowler-cloud/prowler#12885 · 1 条评论 ·
维护者通常 1 天内回复
-
Bug in GaussianTailProbabilityCalibrator: running_statistics=False still uses a windowed variance未关闭bug good first issue
难度 2/5 1-3 小时 新手友好度 88/100
selimfirat/pysad#107 ·
维护者通常 1 天内回复
-
bug ci-failure high priority
难度 1/5 1 小时以内 新手友好度 88/100
vllm-project/vllm-omni#8194 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复