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
{{ message }}
Repository navigation
copy_from_query does not handle NoneType parameters correctly #1179
Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?:
Python version: 3.12.5
Platform: linux
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?: yes
While using copy_from_query command, the handling of None values for the parameters is not processed correctly. The mogrifyfunction in utils looks like it fails to convert the python NoneType into correponding NULL values.
One example could be:
SELECT $1::TEXT IS NULLOR $1='foo'
This would return TRUE if $1 is set to NULL or if $1 is of value foo.. This works well when using fetchrow or similar commands, but fails with the copy_from _query command.
The error reported by Postgres is:
2024-09-08 14:42:51.918 PDT [2489056] srs@srs ERROR: syntax error at or near "::" at character 19
2024-09-08 14:42:51.918 PDT [2489056] srs@srs STATEMENT: COPY (
SELECT ::TEXT IS NULL OR = 'foo'
) TO STDOUT (FORMAT 'csv', HEADER True)
As you can see the parameter is replaced by ::TEXT and the second one to when it should've been: NULL in BOTH cases.
Activity
fobispo-tc commentedon Sep 8, 2024
The fix is simple, at the end of the
_mogrifyfunction in theasyncpg/utilsdirectory, change the return to:fobispo-tc commentedon Sep 8, 2024
PR added here: #1180