Closed fobispotc closed 3 weeks ago
The fix is simple, at the end of the _mogrify
function in the asyncpg/utils
directory, change the return to:
return re.sub(
r"\$(\d+)\b",
lambda m: (
textified[int(m.group(1)) - 1]
if textified[int(m.group(1)) - 1] is not None
else "NULL"
),
query,
)
PR added here: https://github.com/MagicStack/asyncpg/pull/1180
While using
copy_from_query
command, the handling ofNone
values for the parameters is not processed correctly. Themogrify
function in utils looks like it fails to convert the pythonNoneType
into correpondingNULL
values.One example could be:
This would return TRUE if
$1
is set toNULL
or if$1
is of valuefoo
.. This works well when usingfetchrow
or similar commands, but fails with thecopy_from _query
command.The error reported by Postgres is:
As you can see the parameter is replaced by
::TEXT
and the second one to` when it should've been:
NULL` in BOTH cases.