You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: local Postgres in docker
Python version: 3.7.4
Platform: Alpine Linux
Do you use pgbouncer?: no
Did you install asyncpg with pip?: yes
I've made script to reproduce the bug with explanations in comments:
importasynciofromenumimportEnumimportasyncpgclassChoice(Enum):
rock='rock'paper='paper'scissors='scissors'ACTIVATE_KRAKEN=Trueasyncdefmain():
conn=awaitasyncpg.connect('postgresql://postgres@localhost/test')
# make test repeatableawaitconn.execute("DROP TABLE IF EXISTS game")
awaitconn.execute("DROP TYPE IF EXISTS choice")
awaitconn.execute(
"CREATE TYPE choice AS ENUM ('rock', 'paper', 'scissors')")
awaitconn.execute(""" CREATE TABLE game( id serial PRIMARY KEY, ch choice ) """)
awaitconn.execute(
"INSERT INTO game (ch) VALUES ('rock'), ('paper'), ('rock')")
awaitconn.set_type_codec(
'choice',
encoder=lambdac: c.name,
decoder=Choice,
schema='public',
format='text',
)
ifnotACTIVATE_KRAKEN:
# looks like we're preheating some internal cache hereawaitconn.fetchval("SELECT 'paper'::choice")
awaitconn.fetch("SELECT * FROM game WHERE ch = $1", Choice.paper)
# moment when things do happenprint(repr(
awaitconn.fetchval("SELECT '{paper,rock}'::choice[]")
))
# ['paper', 'rock']# ^ it returns reasonable result here, but if we do the followingprint(repr(
awaitconn.fetchval("SELECT 'paper'::choice")
))
print(repr(
awaitconn.fetch("SELECT * FROM game WHERE ch = $1", Choice.paper)
))
# if kraken was asleep, everything is fine:# <Choice.paper: 'paper'># [<Record id=2 ch=<Choice.paper: 'paper'>>]# if kraken has been activated:# 'paper'# asyncpg.exceptions.DataError: invalid input for query argument $1:# <Choice.paper: 'paper'> (expected str, got Choice)asyncio.run(main())
Activity
Untangle custom codec confusion
elprans commentedon Nov 26, 2020
Ouch, this is one gnarly kraken! Thanks for a detailed report. The fix is in #662.
Untangle custom codec confusion
Untangle custom codec confusion (#662)