MagicStack / MagicStack/asyncpg

Unexpected/undesirable `CAST` of date string to `VARCHAR`

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

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

主要言語
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.

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

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

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. 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

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

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