MagicStack / MagicStack/asyncpg
Unexpected/undesirable `CAST` of date string to `VARCHAR`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 8.1k
- Forks
- 468
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
* **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.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- postgresql, python
- Bereich
- backend, databases
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100