MagicStack / MagicStack/asyncpg
Unexpected/undesirable `CAST` of date string to `VARCHAR`
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 8.1k
- フォーク
- 468
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
* **asyncpg version**: 0.29.0
* **PostgreSQL version**: 15.7
* **Python version**: 3.11
* **Platform**: macOS 13.6
* **Do you use pgbouncer?**: no
* **Did you install asyncpg with pip?**: no (poetry)
```python
start_date = '2024-01-01'
query.where(MyTable.datetime_col >= start_date)
```
This will fail:
```
: operator does not exist: timestamp without time zone >= character varying
```
It seems that this is being casted as `VARCHAR`:
```
SELECT * FROM my_table WHERE datetime_col >= $1::VARCHAR
```
This same filter is valid in Postgres
```sql
SELECT * FROM my_table WHERE datetime_col >= '2024-01-01'
```
It works when using the datetime object:
```python
start_date = dt.datetime.strptime(start_date, "%Y-%m-%d")
query.where(MyTable.datetime_col >= start_date)
```
Wonder if this is somewhat similar to #1169 in the sense that casting/argument handling invalidates valid SQL statements.
I'd have imagined that castings were performed in obvious and non-breaking scenarios, and scenarios where casting would be necessary, but are not obvious should be handled directly by the user. Breaking valid SQL statements seems counter intuitive IMHO.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Reproduce the query.where case using asyncpg 0.29.0, PostgreSQL 15.7, and Python 3.11, comparing the string and datetime inputs. Inspect the generated SQL and parameter handling around the reported $1::VARCHAR cast. Done means the expected date comparison behavior is established and covered by a regression test or the issue is shown to belong elsewhere.
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- postgresql, python
- 領域
- backend, databases
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100