MagicStack / MagicStack/asyncpg

negative interval encoding issues due to python's timedelta implementation details

オープン
#1,114 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
8.1k
フォーク
468
PR マージ指標
30日以内にマージされた PR はありません

説明

* **asyncpg version**: 0.29.0
* **PostgreSQL version**: 16.1
* **Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?**: this is happening on local PG
* **Python version**: 3.11.7
* **Platform**:
* **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](https://github.com/magicstack/uvloop)?**: yes

Python's timedelta implementation only allows to store negative number of days, hours, minutes, seconds, microseconds are always positive values. So when a negative value smaller than a day is interpreted it is stored in a strange way, example from Python's documentation:

Note that normalization of negative values may be surprising at first. For example:

```
>>> from datetime import timedelta
>>> d = timedelta(microseconds=-1)
>>> (d.days, d.seconds, d.microseconds)
(-1, 86399, 999999)

```

https://docs.python.org/3/library/datetime.html?highlight=timedelta#datetime.timedelta

In my particular case when I'm trying to store -3 hours, that's getting translated in python to:

```python
datetime.timedelta(days=-1, seconds=75600)
```

And ends up stored in postgresql as: "0 years 0 mons -1 days 21 hours 0 mins 0.0 secs"

Is there also a workaround where I can skip timedelta for interval?

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

No source file or test is named. Start by reproducing the negative three-hour timedelta case with asyncpg 0.29.0, Python 3.11.7, and PostgreSQL 16.1, then trace the interval encoding and decoding behavior. Done means the expected representation or a documented workaround is established, with regression coverage for negative sub-day intervals.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
postgresql, python
領域
databases
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
32/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。