invalid input for query argument (can't subtract offset-naive and offset-aware datetimes)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Ispeziona asyncpg/protocol/prepared_stmt.pyx alla riga 204 e il percorso di codifica dell’argomento timestamp; inizia eseguendo la riproduzione Python/PostgreSQL fornita. Il lavoro è completato quando un aware datetime può essere passato a un timestamp without time zone senza generare l’offset-mismatch error, mentre il caso timestamp with time zone mantiene il comportamento esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
- asyncpg version: 0.29.0
- PostgreSQL version: 13.8
- Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: local postgres 13.8-alpine running in docker - Python version: 3.12.1
- Platform: macos
- 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
I'm getting an error:
File "asyncpg/protocol/prepared_stmt.pyx", line 204, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg
asyncpg.exceptions.DataError: invalid input for query argument $1: datetime.datetime(2024, 3, 21, 21, 17, 9... (can't subtract offset-naive and offset-aware datetimes)
When passing python's datetime object with timezone details to be stored in a column without timezone. Minimal steps to reproduce:
import asyncio
import datetime
import asyncpg
DSN = 'postgresql://user:password@host:port/database'
CREATE_SQL = """
DROP TABLE IF EXISTS timestamps_test;
CREATE TABLE timestamps_test
(
ts_no_tz timestamp without time zone,
ts_tz timestamp with time zone
);
"""
INSERT_SQL = "INSERT INTO timestamps_test (ts_no_tz, ts_tz) VALUES ($1, $2);"
async def main():
conn = await asyncpg.connect(DSN)
try:
await conn.execute(CREATE_SQL)
now = datetime.datetime.fromisoformat("2024-03-21 21:17:09.631169+07:00")
await conn.execute(INSERT_SQL, now, now)
finally:
await conn.close()
if __name__ == '__main__':
asyncio.run(main())
I understand that timezone details would be lost either way, but it's inconsistent with PostgreSQL's native behaviour, when trying to insert the same date with psql:
$ psql
psql (15.6, server 13.8)
Type "help" for help.
INSERT INTO
timestamps_test (ts_no_tz, ts_tz)
VALUES
(TIMESTAMP '2024-03-21 21:17:09.631169+07:00',
TIMESTAMP WITH TIME ZONE '2024-03-21 21:17:09.631169+07:00');
INSERT 0 1
# SELECT * FROM timestamps_test;
ts_no_tz | ts_tz
----------------------------+-------------------------------
2024-03-21 21:17:09.631169 | 2024-03-21 14:17:09.631169+00
(1 row)
timezone info is ignored and lost but there's no error.
- Lingua principale
- Python
- Stelle
- 8.1k
- Fork
- 469
- Merge medio
- 2g 20h
- PR unite (30g)
- 9
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MagicStack/asyncpg
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
MagicStack/asyncpg#1357 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
MagicStack/asyncpg#1354 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
MagicStack/asyncpg#1342 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 56/100
MagicStack/asyncpg#1340 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 28/100
MagicStack/asyncpg#1337 ·
Tutte le issue di MagicStack/asyncpg
Issue simili
-
essnmx good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
-
[Feature] 奇物选择添加优先级 Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
syfoud/Simulated_Scepter#174 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Giskard-AI/giskard-oss#2840 · 1 commento ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Apertaarea: repo bug perceived difficulty: 2
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
yeti-platform/yeti#1380 ·